#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use rocket::http::RawStr; #[get("/")] fn index() -> &'static str { "Hello, world!" } #[get("/hello/")] fn name(name: &RawStr) -> String { format!("Hello, {}!", name.as_str()) } #[get("/hello///")] fn hello(name: String, age: u8, cool: bool) -> String { if cool { format!("You're a cool {} year old, {}!", age, name) } else { format!("{}, we need to talk about your coolness.", name) } } #[get("/hello?wave&")] fn hello_query(name: Option<&RawStr>) -> String { name.map(|name| format!("Hi, {}!", name)) .unwrap_or_else(|| "Hello!".into()) } fn main() { rocket::ignite() .mount("/", routes![index, hello, hello_query, name]) .launch(); }