mirror of https://github.com/rwf2/Rocket.git
Move the form module under request and outcome to top-level.
This commit is contained in:
parent
916bf7310a
commit
37e6a367b8
|
@ -68,7 +68,7 @@ pub fn from_form_derive(ecx: &mut ExtCtxt, span: Span, meta_item: &MetaItem,
|
||||||
span: span,
|
span: span,
|
||||||
attributes: Vec::new(),
|
attributes: Vec::new(),
|
||||||
path: ty::Path {
|
path: ty::Path {
|
||||||
path: vec!["rocket", "form", "FromForm"],
|
path: vec!["rocket", "request", "FromForm"],
|
||||||
lifetime: lifetime_var,
|
lifetime: lifetime_var,
|
||||||
params: vec![],
|
params: vec![],
|
||||||
global: true,
|
global: true,
|
||||||
|
@ -169,7 +169,7 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
|
||||||
let id_str = ident_string.as_str();
|
let id_str = ident_string.as_str();
|
||||||
arms.push(quote_tokens!(cx,
|
arms.push(quote_tokens!(cx,
|
||||||
$id_str => {
|
$id_str => {
|
||||||
$ident = match ::rocket::form::FromFormValue::from_form_value(v) {
|
$ident = match ::rocket::request::FromFormValue::from_form_value(v) {
|
||||||
Ok(v) => Some(v),
|
Ok(v) => Some(v),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("\tError parsing form val '{}': {:?}", $id_str, e);
|
println!("\tError parsing form val '{}': {:?}", $id_str, e);
|
||||||
|
@ -183,7 +183,7 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
|
||||||
// The actual match statement. Iterate through all of the fields in the form
|
// The actual match statement. Iterate through all of the fields in the form
|
||||||
// and use the $arms generated above.
|
// and use the $arms generated above.
|
||||||
stmts.push(quote_stmt!(cx,
|
stmts.push(quote_stmt!(cx,
|
||||||
for (k, v) in ::rocket::form::FormItems($arg) {
|
for (k, v) in ::rocket::request::FormItems($arg) {
|
||||||
match k {
|
match k {
|
||||||
$arms
|
$arms
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -205,7 +205,7 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
|
||||||
|
|
||||||
failure_conditions.push(quote_tokens!(cx,
|
failure_conditions.push(quote_tokens!(cx,
|
||||||
if $ident.is_none() &&
|
if $ident.is_none() &&
|
||||||
<$ty as ::rocket::form::FromFormValue>::default().is_none() {
|
<$ty as ::rocket::request::FromFormValue>::default().is_none() {
|
||||||
println!("\t'{}' did not parse.", stringify!($ident));
|
println!("\t'{}' did not parse.", stringify!($ident));
|
||||||
true
|
true
|
||||||
} else { false }
|
} else { false }
|
||||||
|
@ -218,7 +218,7 @@ fn from_form_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substruct
|
||||||
for &(ref ident, ty) in &fields_and_types {
|
for &(ref ident, ty) in &fields_and_types {
|
||||||
result_fields.push(quote_tokens!(cx,
|
result_fields.push(quote_tokens!(cx,
|
||||||
$ident: $ident.unwrap_or_else(||
|
$ident: $ident.unwrap_or_else(||
|
||||||
<$ty as ::rocket::form::FromFormValue>::default().unwrap()
|
<$ty as ::rocket::request::FromFormValue>::default().unwrap()
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl RouteGenerateExt for RouteParams {
|
||||||
let ty = strip_ty_lifetimes(arg.ty.clone());
|
let ty = strip_ty_lifetimes(arg.ty.clone());
|
||||||
Some(quote_stmt!(ecx,
|
Some(quote_stmt!(ecx,
|
||||||
let $name: $ty =
|
let $name: $ty =
|
||||||
match ::rocket::form::FromForm::from_form_string($form_string) {
|
match ::rocket::request::FromForm::from_form_string($form_string) {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(_) => return ::rocket::Response::forward()
|
Err(_) => return ::rocket::Response::forward()
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
use rocket::form::FromForm;
|
use rocket::request::{FromForm, FromFormValue};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, FromForm)]
|
#[derive(Debug, PartialEq, FromForm)]
|
||||||
struct TodoTask {
|
struct TodoTask {
|
||||||
|
@ -17,8 +17,6 @@ enum FormOption {
|
||||||
A, B, C
|
A, B, C
|
||||||
}
|
}
|
||||||
|
|
||||||
use rocket::form::FromFormValue;
|
|
||||||
|
|
||||||
impl<'v> FromFormValue<'v> for FormOption {
|
impl<'v> FromFormValue<'v> for FormOption {
|
||||||
type Error = &'v str;
|
type Error = &'v str;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ extern crate rocket;
|
||||||
mod files;
|
mod files;
|
||||||
|
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket::form::FromFormValue;
|
use rocket::request::FromFormValue;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct StrongPassword<'r>(&'r str);
|
struct StrongPassword<'r>(&'r str);
|
||||||
|
|
|
@ -3,9 +3,8 @@
|
||||||
|
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
use rocket::Request;
|
use rocket::request::{Request, FromFormValue};
|
||||||
use rocket::response::NamedFile;
|
use rocket::response::NamedFile;
|
||||||
use rocket::form::FromFormValue;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
// TODO: Make deriving `FromForm` for this enum possible.
|
// TODO: Make deriving `FromForm` for this enum possible.
|
||||||
|
|
|
@ -6,7 +6,7 @@ extern crate rocket;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
|
|
||||||
use rocket::{Request, Error};
|
use rocket::{Request};
|
||||||
use rocket::response::Redirect;
|
use rocket::response::Redirect;
|
||||||
use rocket_contrib::Template;
|
use rocket_contrib::Template;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ extern crate serde_json;
|
||||||
#[macro_use] extern crate rocket_contrib;
|
#[macro_use] extern crate rocket_contrib;
|
||||||
#[macro_use] extern crate serde_derive;
|
#[macro_use] extern crate serde_derive;
|
||||||
|
|
||||||
use rocket::{Request, Error};
|
|
||||||
use rocket_contrib::JSON;
|
use rocket_contrib::JSON;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
|
@ -70,9 +70,9 @@ extern crate toml;
|
||||||
|
|
||||||
#[doc(hidden)] #[macro_use] pub mod logger;
|
#[doc(hidden)] #[macro_use] pub mod logger;
|
||||||
#[doc(hidden)] pub mod http;
|
#[doc(hidden)] pub mod http;
|
||||||
pub mod form;
|
|
||||||
pub mod request;
|
pub mod request;
|
||||||
pub mod response;
|
pub mod response;
|
||||||
|
pub mod outcome;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
mod router;
|
mod router;
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
pub struct Data {
|
|
||||||
stream: Box<Read>
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait FromData {
|
|
||||||
fn from_data(data: Data) -> Outcome { }
|
|
||||||
}
|
|
|
@ -71,7 +71,7 @@ impl<'f> FromForm<'f> for &'f str {
|
||||||
/// might define a new type and implement `FromFormValue` as follows:
|
/// might define a new type and implement `FromFormValue` as follows:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use rocket::form::FromFormValue;
|
/// use rocket::request::FromFormValue;
|
||||||
/// use rocket::Error;
|
/// use rocket::Error;
|
||||||
///
|
///
|
||||||
/// struct AdultAge(usize);
|
/// struct AdultAge(usize);
|
||||||
|
@ -210,7 +210,7 @@ impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Result<T, T::Error> {
|
||||||
/// `FormItems` can be used directly as an iterator:
|
/// `FormItems` can be used directly as an iterator:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use rocket::form::FormItems;
|
/// use rocket::request::FormItems;
|
||||||
///
|
///
|
||||||
/// // prints "greeting = hello" then "username = jake"
|
/// // prints "greeting = hello" then "username = jake"
|
||||||
/// let form_string = "greeting=hello&username=jake";
|
/// let form_string = "greeting=hello&username=jake";
|
||||||
|
@ -222,7 +222,7 @@ impl<'v, T: FromFormValue<'v>> FromFormValue<'v> for Result<T, T::Error> {
|
||||||
/// This is the same example as above, but the iterator is used explicitly.
|
/// This is the same example as above, but the iterator is used explicitly.
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use rocket::form::FormItems;
|
/// use rocket::request::FormItems;
|
||||||
///
|
///
|
||||||
/// let form_string = "greeting=hello&username=jake";
|
/// let form_string = "greeting=hello&username=jake";
|
||||||
/// let mut items = FormItems(form_string);
|
/// let mut items = FormItems(form_string);
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
mod request;
|
mod request;
|
||||||
mod param;
|
mod param;
|
||||||
|
mod form;
|
||||||
mod from_request;
|
mod from_request;
|
||||||
|
|
||||||
pub use self::request::Request;
|
pub use self::request::Request;
|
||||||
pub use self::from_request::FromRequest;
|
pub use self::from_request::FromRequest;
|
||||||
pub use self::param::{FromParam, FromSegments};
|
pub use self::param::{FromParam, FromSegments};
|
||||||
|
pub use self::form::{FromForm, FromFormValue, FormItems};
|
||||||
|
|
|
@ -2,7 +2,6 @@ mod empty;
|
||||||
mod responder;
|
mod responder;
|
||||||
mod redirect;
|
mod redirect;
|
||||||
mod with_status;
|
mod with_status;
|
||||||
mod outcome;
|
|
||||||
mod flash;
|
mod flash;
|
||||||
mod named_file;
|
mod named_file;
|
||||||
mod stream;
|
mod stream;
|
||||||
|
@ -13,11 +12,11 @@ pub use self::responder::Responder;
|
||||||
pub use self::empty::{Empty, Forward};
|
pub use self::empty::{Empty, Forward};
|
||||||
pub use self::redirect::Redirect;
|
pub use self::redirect::Redirect;
|
||||||
pub use self::with_status::StatusResponse;
|
pub use self::with_status::StatusResponse;
|
||||||
pub use self::outcome::{Outcome, ResponseOutcome};
|
|
||||||
pub use self::flash::Flash;
|
pub use self::flash::Flash;
|
||||||
pub use self::named_file::NamedFile;
|
pub use self::named_file::NamedFile;
|
||||||
pub use self::stream::Stream;
|
pub use self::stream::Stream;
|
||||||
pub use self::data::Content;
|
pub use self::data::Content;
|
||||||
|
pub use outcome::{Outcome, ResponseOutcome};
|
||||||
|
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use http::hyper::StatusCode;
|
use http::hyper::StatusCode;
|
||||||
|
|
|
@ -8,11 +8,10 @@ use term_painter::ToStyle;
|
||||||
|
|
||||||
use config;
|
use config;
|
||||||
use logger;
|
use logger;
|
||||||
use request::Request;
|
use request::{Request, FormItems};
|
||||||
use router::{Router, Route};
|
use router::{Router, Route};
|
||||||
use catcher::{self, Catcher};
|
use catcher::{self, Catcher};
|
||||||
use response::Outcome;
|
use outcome::Outcome;
|
||||||
use form::FormItems;
|
|
||||||
use error::Error;
|
use error::Error;
|
||||||
|
|
||||||
use http::Method;
|
use http::Method;
|
||||||
|
|
Loading…
Reference in New Issue