#[macro_use] extern crate rocket; use rocket::tokio::time::{sleep, Duration}; use rocket::form::Form; use rocket_dyn_templates::{Template, context}; #[derive(FromForm)] struct Note<'r> { title: &'r str, description: &'r str, } #[post("/form", data="")] async fn form(note: Form>) -> String { format!("New note: {} with description\n{}.", note.title, note.description) } #[get("/hello/")] async fn hello(name: &str) -> String { format!("Hello, {}", name) } fn test1() -> Vec { Vec::new() } #[get("/")] async fn index() -> Template { let notes: Vec> = Vec::new(); notes.append(Note{ title: "Test", description: "Test" }); Template::render("index", context!{ title: "Home", name: "Tait Hoyem" }) } #[get("/delay/")] async fn delay(seconds: u64) -> String { sleep(Duration::from_secs(seconds)).await; format!("Waited for {} seconds", seconds) } #[rocket::main] async fn main() -> Result<(), rocket::Error> { let _rocket = rocket::build() .mount("/", routes![index, delay, hello, form]) .attach(Template::fairing()) .launch() .await?; Ok(()) }