2017-08-29 03:14:59 +00:00
|
|
|
#![feature(plugin, decl_macro, custom_derive)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-09-05 02:18:08 +00:00
|
|
|
|
|
|
|
extern crate rocket;
|
|
|
|
|
2016-12-29 03:29:12 +00:00
|
|
|
#[cfg(test)] mod tests;
|
|
|
|
|
2016-09-05 02:18:08 +00:00
|
|
|
#[derive(FromForm)]
|
2017-03-31 06:06:53 +00:00
|
|
|
struct Person {
|
|
|
|
name: String,
|
2016-09-05 02:18:08 +00:00
|
|
|
age: Option<u8>
|
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/hello?<person>")]
|
|
|
|
fn hello(person: Person) -> String {
|
|
|
|
if let Some(age) = person.age {
|
|
|
|
format!("Hello, {} year old named {}!", age, person.name)
|
|
|
|
} else {
|
|
|
|
format!("Hello {}!", person.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2017-03-16 05:10:09 +00:00
|
|
|
rocket::ignite().mount("/", routes![hello]).launch();
|
2016-09-05 02:18:08 +00:00
|
|
|
}
|