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

pub struct LenientForm<T>(pub T);

A data guard 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.


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>.


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;

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:

forms = 524288


impl<T> LenientForm<T>[src]

pub fn into_inner(self) -> T[src]

Consumes self and returns the parsed value.


use rocket::request::LenientForm;

struct MyForm {
    field: String,

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

Trait Implementations

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

type Error = <T as FromForm<'q>>::Error

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

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

type Error = FormDataError<'f, T::Error>

The associated error to be returned when the guard fails.

type Owned = String

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

type Borrowed = str

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

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

type Target = T

The resulting type after dereferencing.

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

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

type Target = T::Target

The resulting type of this conversion.

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

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

impl<T> Typeable for T where
    T: Any

fn get_type(&self) -> TypeId

Get the TypeId of this object.

impl<T> IntoCollection<T> for T

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