[][src]Struct rocket::request::LenientForm

pub struct LenientForm<T>(_);

A data gaurd for parsing FromForm types leniently.

This type implements the FromData trait, and like Form, provides a generic means to parse arbitrary structures from incoming form data. Unlike Form, this type uses a lenient parsing strategy: forms that contains a superset of the expected fields (i.e, extra fields) will parse successfully.

Leniency

A LenientForm<T> will parse successfully from an incoming form if the form contains a superset of the fields in T. Said another way, a LenientForm<T> automatically discards extra fields without error. For instance, if an incoming form contains the fields "a", "b", and "c" while T only contains "a" and "c", the form will parse as LenientForm<T>.

Usage

The usage of a LenientForm type is equivalent to that of Form, so we defer details to its documentation.

LenientForm implements FromData, so it can be used directly as a target of the data = "<param>" route parameter. For instance, if some structure of type T implements the FromForm trait, an incoming form can be automatically parsed into the T structure with the following route and handler:

use rocket::request::LenientForm;

#[derive(FromForm)]
struct UserInput {
    value: String
}

#[post("/submit", data = "<user_input>")]
fn submit_task(user_input: LenientForm<UserInput>) -> String {
    format!("Your value: {}", user_input.value)
}

Incoming Data Limits

A LenientForm obeys the same data limits as a Form and defaults to 32KiB. The limit can be increased by setting the limits.forms configuration parameter. For instance, to increase the forms limit to 512KiB for all environments, you may add the following to your Rocket.toml:

[global.limits]
forms = 524288

Methods

impl<T> LenientForm<T>
[src]

Consumes self and returns the parsed value.

Example

use rocket::request::LenientForm;

#[derive(FromForm)]
struct MyForm {
    field: String,
}

#[post("/submit", data = "<form>")]
fn submit(form: LenientForm<MyForm>) -> String {
    form.into_inner().field
}

Trait Implementations

impl<'q, T: FromForm<'q>> FromQuery<'q> for LenientForm<T>
[src]

The associated error to be returned if parsing/validation fails.

Parses and validates an instance of Self from a query or returns an Error if parsing or validation fails. Read more

impl<'f, T: FromForm<'f>> FromData<'f> for LenientForm<T>
[src]

The associated error to be returned when the guard fails.

The owned type returned from FromData::transform(). Read more

The borrowed type consumed by FromData::from_data() when FromData::transform() returns a Transform::Borrowed. Read more

Transforms data into a value of type Self::Owned. Read more

Validates, parses, and converts the incoming request body data into an instance of Self. Read more

impl<T> Deref for LenientForm<T>
[src]

The resulting type after dereferencing.

Dereferences the value.

impl<T: Debug> Debug for LenientForm<T>
[src]

Formats the value using the given formatter. Read more

impl<'f, A, T: FromUriParam<A> + FromForm<'f>> FromUriParam<A> for LenientForm<T>
[src]

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

Auto Trait Implementations

impl<T> Send for LenientForm<T> where
    T: Send

impl<T> Sync for LenientForm<T> where
    T: Sync

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> FromUriParam for T where
    T: UriDisplay

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

impl<'a, T> FromUriParam for T where
    T: UriDisplay

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

impl<'a, T> FromUriParam for T where
    T: UriDisplay

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

impl<T> IntoCollection for T

Important traits for SmallVec<A>

Converts self into a collection.

Important traits for SmallVec<A>

impl<T, I> AsResult for T where
    I: Input,