Struct rocket_enumform::UrlEncoded [−][src]
#[repr(transparent)]pub struct UrlEncoded<T>(pub T);
Expand description
The UrlEncoded guard: easily consume x-www-form-urlencoded requests.
Receiving
UrlEncoded
is both a data guard and a form guard.
Data Guard
To deserialize request body data from x-www-form-urlencoded, add a data
route argument with a target type of UrlEncoded<T>
, where T
is some type
you’d like to parse. T
must implement serde::Deserialize
. See
serde_urlencoded
docs on the flatten-workaround for important hints about
more complex datatypes.
use rocket_enumform::UrlEncoded;
#[post("/user", format = "form", data = "<user>")]
fn new_user(user: UrlEncoded<User>) {
/* ... */
}
You don’t need to use format = "form"
, but it may be what you
want. Using format = urlencoded
means that any request that doesn’t
specify “application/x-www-form-urlencoded” as its Content-Type
header
value will not be routed to the handler.
Incoming Data Limits
The default size limit for incoming UrlEncoded data is the built in form
limit. Setting a limit protects your application from denial of service
(DoS) attacks and from resource exhaustion through high memory consumption.
The limit can be increased by setting the limits.form
configuration
parameter. For instance, to increase the UrlEncoded limit to 5MiB for all
environments, you may add the following to your Rocket.toml
:
[global.limits]
form = 5242880
Tuple Fields
0: T
Implementations
Consumes the UrlEncoded wrapper and returns the wrapped item.
Example
use rocket_enumform::UrlEncoded;
let string = "Hello".to_string();
let outer = UrlEncoded(string);
assert_eq!(outer.into_inner(), "Hello".to_string());
Trait Implementations
Asynchronously validates, parses, and converts an instance of Self
from the incoming request body data. Read more
type Target = UrlEncoded<&'a T>
type Target = UrlEncoded<&'a T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
type Target = UrlEncoded<&'a mut T>
type Target = UrlEncoded<&'a mut T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
type Target = &'x UrlEncoded<T>
type Target = &'x UrlEncoded<T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
type Target = &'x mut UrlEncoded<T>
type Target = &'x mut UrlEncoded<T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
type Target = UrlEncoded<T>
type Target = UrlEncoded<T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
type Target = UrlEncoded<T>
type Target = UrlEncoded<T>
The resulting type of this conversion.
Converts a value of type T
into a value of type Self::Target
. The
resulting value of type Self::Target
will be rendered into a URI using
its [UriDisplay
] implementation. Read more
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Serializes the wrapped value into UrlEncoding. Returns a response with Content-Type
application/x-www-form-urlencode and a fixed-size body with the serialized value. If serialization
fails, an Err
of Status::InternalServerError
is returned.
Returns Ok
if a Response
could be generated successfully. Otherwise,
returns an Err
with a failing Status
. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for UrlEncoded<T> where
T: RefUnwindSafe,
impl<T> Send for UrlEncoded<T> where
T: Send,
impl<T> Sync for UrlEncoded<T> where
T: Sync,
impl<T> Unpin for UrlEncoded<T> where
T: Unpin,
impl<T> UnwindSafe for UrlEncoded<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more