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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Mutably dereferences the value.

Performs the conversion.

The associated error to be returned when the guard fails.

Asynchronously validates, parses, and converts an instance of Self from the incoming request body data. Read more

Parse a value of T from a form value field. Read more

Parse a value of T from a form data field. Read more

Returns a default value, if any exists, to be used during lenient parsing when the form field is missing. Read more

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

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

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

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

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

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

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. 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

This method tests greater than or equal to (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

Formats self in a URI-safe manner using the given formatter.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The form guard’s parsing context.

Initializes and returns the parsing context for Self.

Processes the value field field.

Processes the data field field.

Finalizes parsing. Returns the parsed value when successful or collection of Errors otherwise. Read more

Processes the external form or field error _error. Read more

Returns a default value, if any, to use when a value is desired and parsing fails. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Converts self into a collection.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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