#![feature(proc_macro_hygiene, decl_macro)] #[macro_use] extern crate rocket; #[macro_use] extern crate serde; //use rocket::request::FromSegments; //use rocket::http::uri::Segments; //use rocket_contrib::serve::StaticFiles; use rocket_contrib::templates::Template; mod store; use crate::store::Store; use rocket::State; use parking_lot::RwLock; use rocket::response::Redirect; use rocket::http::Status; use rocket::request::Form; use std::collections::HashMap; #[get("/")] fn index(store : State>) -> Template { let mut context = HashMap::new(); let rg = store.read(); context.insert("records", &rg.parts); Template::render("index", context) } #[post("/add", data="")] fn add_part(store : State>, record : Form) -> Redirect { store.write().add(record.into_inner()); Redirect::to(uri!(index)) } fn main() { rocket::ignite() .attach(Template::fairing()) .manage(RwLock::new(Store::new())) .mount("/", routes![index, add_part]).launch(); }