mirror of https://github.com/rwf2/Rocket.git
Reexport derive macros alongside derived traits.
This commit is contained in:
parent
ca1e6e0cf7
commit
8e7100f8f7
|
@ -1,4 +1,4 @@
|
|||
#[macro_use] extern crate rocket;
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::request::FromFormValue;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
#[macro_use] extern crate rocket;
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::local::Client;
|
||||
use rocket::response::Responder;
|
||||
|
|
|
@ -10,6 +10,8 @@ mod query;
|
|||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
#[doc(hidden)] pub use rocket_codegen::{FromForm, FromFormValue};
|
||||
|
||||
pub use self::request::Request;
|
||||
pub use self::from_request::{FromRequest, Outcome};
|
||||
pub use self::param::{FromParam, FromSegments};
|
||||
|
|
|
@ -31,6 +31,8 @@ crate mod flash;
|
|||
pub mod content;
|
||||
pub mod status;
|
||||
|
||||
#[doc(hidden)] pub use rocket_codegen::Responder;
|
||||
|
||||
pub use self::response::{Response, ResponseBuilder, Body, DEFAULT_CHUNK_SIZE};
|
||||
pub use self::responder::Responder;
|
||||
pub use self::redirect::Redirect;
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
#![feature(proc_macro_hygiene, decl_macro)]
|
||||
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::{get, routes};
|
||||
use rocket::request::{Form, FromForm, FromFormValue};
|
||||
use rocket::response::Responder;
|
||||
|
||||
#[derive(FromFormValue)]
|
||||
enum Thing {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Thing {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match *self {
|
||||
Thing::A => write!(f, "a"),
|
||||
Thing::B => write!(f, "b"),
|
||||
Thing::C => write!(f, "c"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(FromForm)]
|
||||
struct ThingForm {
|
||||
thing: Thing,
|
||||
}
|
||||
|
||||
#[derive(Responder)]
|
||||
struct DerivedResponder {
|
||||
data: String,
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
fn index() -> DerivedResponder {
|
||||
DerivedResponder { data: "hello".to_string() }
|
||||
}
|
||||
|
||||
#[get("/?<params..>")]
|
||||
fn number(params: Form<ThingForm>) -> DerivedResponder {
|
||||
DerivedResponder { data: params.thing.to_string() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_derive_reexports() {
|
||||
use rocket::local::Client;
|
||||
|
||||
let rocket = rocket::ignite().mount("/", routes![index, number]);
|
||||
let client = Client::new(rocket).unwrap();
|
||||
|
||||
let mut response = client.get("/").dispatch();
|
||||
assert_eq!(response.body_string().unwrap(), "hello");
|
||||
|
||||
let mut response = client.get("/?thing=b").dispatch();
|
||||
assert_eq!(response.body_string().unwrap(), "b");
|
||||
}
|
Loading…
Reference in New Issue