2018-08-07 02:58:07 +00:00
|
|
|
#![feature(plugin, decl_macro)]
|
2016-09-09 03:38:58 +00:00
|
|
|
#![plugin(rocket_codegen)]
|
2016-09-05 02:18:08 +00:00
|
|
|
|
2018-08-07 02:58:07 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2016-09-05 02:18:08 +00:00
|
|
|
|
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
|
|
|
}
|