#[macro_use] extern crate rocket; #[cfg(test)] mod tests; use rocket::Request; use rocket::response::{content, status}; use rocket::http::Status; #[get("/hello//")] fn hello(name: String, age: i8) -> String { format!("Hello, {} year old named {}!", age, name) } #[get("/")] fn forced_error(code: u16) -> Status { Status::raw(code) } #[catch(404)] fn not_found(req: &Request<'_>) -> content::Html { content::Html(format!("

Sorry, but '{}' is not a valid path!

Try visiting /hello/<name>/<age> instead.

", req.uri())) } #[catch(default)] fn default_catcher(status: Status, req: &Request<'_>) -> status::Custom { let msg = format!("{} - {} ({})", status.code, status.reason, req.uri()); status::Custom(status, msg) } fn rocket() -> rocket::Rocket { rocket::ignite() // .mount("/", routes![hello, hello]) // uncoment this to get an error .mount("/", routes![hello, forced_error]) .register(catchers![not_found, default_catcher]) } #[rocket::main] async fn main() { if let Err(e) = rocket().launch().await { println!("Whoops! Rocket didn't launch!"); println!("Error: {:?}", e); }; }