Rocket/core/codegen/tests/complete-decorator.rs
Sergio Benitez d7f6d82fe4 Implement 'FromForm[Value]', 'Responder' proc-macro derives.
This completes the migration of custom derives to proc-macros, removing
the need for the `custom_derive` feature in consumer code. This commit
also includes documentation, unit tests, and compile UI tests for each
of the derives.

Additionally, this commit improves the existing `FromForm` and
`FromFormValue` derives. The generated code for `FromForm` now returns
an error value indicating the error condition. The `FromFormValue`
derive now accepts a `form` attribute on variants for specifying the
exact value string to match against.

Closes #590.
Closes #670.
2018-08-06 19:58:07 -07:00

29 lines
560 B
Rust

#![feature(plugin, decl_macro)]
#![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<'r>(
_name: &RawStr,
_query: User<'r>,
user: Form<'r, User<'r>>,
_cookies: Cookies
) -> String {
format!("{}:{}", user.get().name, user.get().nickname)
}
#[test]
fn main() {
let _ = routes![get];
}