Skip to main content

FromForm

Trait FromForm 

Source
pub trait FromForm: Sized {
    type Builder: FormBuilder<Output = Self> + Default;

    // Provided methods
    fn from_urlencoded(input: &[u8]) -> Result<Self, FormError> { ... }
    fn from_query(query: &[u8]) -> Result<Self, FormError> { ... }
    fn from_multipart(
        content_type: &[u8],
        body: &[u8],
    ) -> Result<Self, FormError> { ... }
    fn from_body(content_type: &[u8], body: &[u8]) -> Result<Self, FormError> { ... }
    fn from_urlencoded_with(
        input: &[u8],
        limits: &Limits,
        policy: &Policy,
    ) -> Result<Self, FormError> { ... }
    fn from_body_with(
        content_type: &[u8],
        body: &[u8],
        limits: &Limits,
        policy: &Policy,
    ) -> Result<Self, FormError> { ... }
    fn from_body_inspected<I: Inspector>(
        content_type: &[u8],
        body: &[u8],
        limits: &Limits,
        policy: &Policy,
        inspector: &mut I,
    ) -> Result<Self, FormError> { ... }
    fn from_upload(upload: Upload) -> Result<Self, FormError> { ... }
}
Available on crate feature alloc only.
Expand description

A struct that can be read from a form. Implemented by form!; every method is provided.

§Examples

use form_net::FromForm;

form_net::form! {
    pub struct Login {
        pub email: String,
        pub password: form_net::Secret,
        pub remember: bool,
    }
    ignore = ["csrf_token"];
}

let login = Login::from_body(b"application/x-www-form-urlencoded", b"email=a%40b.example&password=x&csrf_token=t")?;
assert_eq!((login.email.as_str(), login.remember), ("a@b.example", false));

Required Associated Types§

Source

type Builder: FormBuilder<Output = Self> + Default

The builder that collects the fields.

Provided Methods§

Source

fn from_urlencoded(input: &[u8]) -> Result<Self, FormError>

From a urlencoded body, with the default limits and policy.

§Errors

The parser’s errors; Extract { .. }.

Source

fn from_query(query: &[u8]) -> Result<Self, FormError>

From a query string; one leading ? is stripped.

§Errors

As from_urlencoded.

Source

fn from_multipart(content_type: &[u8], body: &[u8]) -> Result<Self, FormError>

From a buffered multipart/form-data body.

§Errors

The parser’s errors; Extract { .. }.

Source

fn from_body(content_type: &[u8], body: &[u8]) -> Result<Self, FormError>

From either encoding, by the Content-Type.

§Errors

UnsupportedMediaType; the parsers’ errors; Extract { .. }.

Source

fn from_urlencoded_with( input: &[u8], limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>

From a urlencoded body with explicit limits and policy.

§Errors

As from_urlencoded; InvalidLimits.

Source

fn from_body_with( content_type: &[u8], body: &[u8], limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>

From either encoding with explicit limits and policy.

§Errors

As from_body; InvalidLimits.

Source

fn from_body_inspected<I: Inspector>( content_type: &[u8], body: &[u8], limits: &Limits, policy: &Policy, inspector: &mut I, ) -> Result<Self, FormError>

From either encoding, with an inspector in the same pass: the inspector and the struct see the same bytes.

§Errors

As from_body_with; Refused.

Source

fn from_upload(upload: Upload) -> Result<Self, FormError>

Available on crate feature fs only.

From a finished upload: text fields as text, files moved into the struct as StoredFiles.

§Errors

Extract { .. }.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§