#![feature(plugin, decl_macro)] #![plugin(rocket_codegen)] #[macro_use] extern crate rocket; use std::io; use rocket::request::Form; use rocket::response::NamedFile; use rocket::http::RawStr; #[cfg(test)] mod tests; #[derive(Debug, FromFormValue)] enum FormOption { A, B, C } #[derive(Debug, FromForm)] struct FormInput<'r> { checkbox: bool, number: usize, #[form(field = "type")] radio: FormOption, password: &'r RawStr, #[form(field = "textarea")] text_area: String, select: FormOption, } #[post("/", data = "")] fn sink<'r>(sink: Result>, Option>) -> String { match sink { Ok(form) => format!("{:?}", form.get()), Err(Some(f)) => format!("Invalid form input: {}", f), Err(None) => format!("Form input was invalid UTF8."), } } #[get("/")] fn index() -> io::Result { NamedFile::open("static/index.html") } fn rocket() -> rocket::Rocket { rocket::ignite().mount("/", routes![index, sink]) } fn main() { rocket().launch(); }