#![feature(proc_macro_non_items, proc_macro_gen, decl_macro)] #[macro_use] extern crate rocket; #[cfg(test)] mod tests; use rocket::request::{Form, LenientForm}; #[derive(FromForm)] struct Person { name: String, age: Option } #[get("/hello?")] fn hello(person: Option>) -> String { if let Some(person) = person { if let Some(age) = person.age { format!("Hello, {} year old named {}!", age, person.name) } else { format!("Hello {}!", person.name) } } else { "We're gonna need a name, and only a name.".into() } } #[get("/hello?age=20&")] fn hello_20(person: LenientForm) -> String { format!("20 years old? Hi, {}!", person.name) } fn rocket() -> rocket::Rocket { rocket::ignite().mount("/", routes![hello, hello_20]) } fn main() { rocket().launch(); }