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§
Sourcetype Builder: FormBuilder<Output = Self> + Default
type Builder: FormBuilder<Output = Self> + Default
The builder that collects the fields.
Provided Methods§
Sourcefn from_urlencoded(input: &[u8]) -> Result<Self, FormError>
fn from_urlencoded(input: &[u8]) -> Result<Self, FormError>
From a urlencoded body, with the default limits and policy.
§Errors
The parser’s errors; Extract { .. }.
Sourcefn from_query(query: &[u8]) -> Result<Self, FormError>
fn from_query(query: &[u8]) -> Result<Self, FormError>
Sourcefn from_body(content_type: &[u8], body: &[u8]) -> Result<Self, FormError>
fn from_body(content_type: &[u8], body: &[u8]) -> Result<Self, FormError>
From either encoding, by the Content-Type.
§Errors
UnsupportedMediaType; the parsers’ errors; Extract { .. }.
Sourcefn from_urlencoded_with(
input: &[u8],
limits: &Limits,
policy: &Policy,
) -> Result<Self, FormError>
fn from_urlencoded_with( input: &[u8], limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>
Sourcefn from_body_with(
content_type: &[u8],
body: &[u8],
limits: &Limits,
policy: &Policy,
) -> Result<Self, FormError>
fn from_body_with( content_type: &[u8], body: &[u8], limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>
Sourcefn from_body_inspected<I: Inspector>(
content_type: &[u8],
body: &[u8],
limits: &Limits,
policy: &Policy,
inspector: &mut I,
) -> Result<Self, FormError>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".