#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; use rocket::response::content::Html; use rocket::response::Redirect; use rocket::request::Form; type Session<'a> = rocket_session::Session<'a, Vec>; fn main() { rocket::ignite() .attach(Session::fairing()) .mount("/", routes![index, add, remove]) .launch(); } #[get("/")] fn index(session: Session) -> Html { let mut page = String::new(); page.push_str(r#"

My Dogs

Add Dog:
"#); Html(page) } #[derive(FromForm)] struct AddForm { name: String, } #[post("/add", data="")] fn add(session: Session, dog : Form) -> Redirect { session.tap(move |sess| { sess.push(dog.into_inner().name); }); Redirect::found("/") } #[get("/remove/")] fn remove(session: Session, dog : usize) -> Redirect { session.tap(|sess| { if dog < sess.len() { sess.remove(dog); } }); Redirect::found("/") }