2016-09-05 02:18:08 +00:00
|
|
|
#![feature(plugin, 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)]
|
|
|
|
struct Person<'r> {
|
|
|
|
name: &'r str,
|
|
|
|
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
|
|
|
}
|