mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-16 22:49:06 +00:00
ec4cc3a293
The new 'FromData' trait allows an implementor to instruct the caller to maintain state on its stack and later pass a borrow for processing. Among other things, it greatly simplifies the 'Form' type, removing a use of unsafe, and allows references in deserialized data guards.
29 lines
554 B
Rust
29 lines
554 B
Rust
#![feature(plugin, decl_macro, proc_macro_non_items)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::http::{Cookies, RawStr};
|
|
use rocket::request::Form;
|
|
|
|
#[derive(FromForm)]
|
|
struct User<'a> {
|
|
name: &'a RawStr,
|
|
nickname: String,
|
|
}
|
|
|
|
#[post("/<_name>?<_query>", format = "application/json", data = "<user>", rank = 2)]
|
|
fn get(
|
|
_name: &RawStr,
|
|
_query: User,
|
|
user: Form<User>,
|
|
_cookies: Cookies
|
|
) -> String {
|
|
format!("{}:{}", user.name, user.nickname)
|
|
}
|
|
|
|
#[test]
|
|
fn main() {
|
|
let _ = routes![get];
|
|
}
|