#![feature(plugin, decl_macro, proc_macro_non_items)] #![plugin(rocket_codegen)] #[macro_use] extern crate rocket; use std::io; use rocket::request::{Form, FormError, FormDataError}; 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(sink: Result, FormError>) -> String { match sink { Ok(form) => format!("{:?}", &*form), Err(FormDataError::Io(_)) => format!("Form input was invalid UTF-8."), Err(FormDataError::Malformed(f)) | Err(FormDataError::Parse(_, f)) => { format!("Invalid form input: {}", f) } } } #[get("/")] fn index() -> io::Result { NamedFile::open("static/index.html") } fn rocket() -> rocket::Rocket { rocket::ignite().mount("/", routes![index, sink]) } fn main() { rocket().launch(); }