pub struct Form<T>(pub T);Expand description
URL encoded payload extractor and responder.
Form has two uses: URL encoded responses, and extracting typed data from URL request payloads.
Extractor
To extract typed data from a request body, the inner type T must implement the
DeserializeOwned trait.
Use FormConfig to configure extraction options.
use actix_web::{post, web};
use serde::Deserialize;
#[derive(Deserialize)]
struct Info {
    name: String,
}
// This handler is only called if:
// - request headers declare the content type as `application/x-www-form-urlencoded`
// - request payload is deserialized into a `Info` struct from the URL encoded format
#[post("/")]
async fn index(form: web::Form<Info>) -> String {
    format!("Welcome {}!", form.name)
}Responder
The Form type also allows you to create URL encoded responses:
simply return a value of type Formserde::Serialize.
Responses use
use actix_web::{get, web};
use serde::Serialize;
#[derive(Serialize)]
struct SomeForm {
    name: String,
    age: u8
}
// Response will have:
// - status: 200 OK
// - header: `Content-Type: application/x-www-form-urlencoded`
// - body: `name=actix&age=123`
#[get("/")]
async fn index() -> web::Form<SomeForm> {
    web::Form(SomeForm {
        name: "actix".into(),
        age: 123
    })
}Panics
URL encoded forms consist of unordered key=value pairs, therefore they cannot be decoded into
any type which depends upon data ordering (eg. tuples). Trying to do so will result in a panic.
Tuple Fields
0: TImplementations
sourceimpl<T> Form<T>
 
impl<T> Form<T>
sourcepub fn into_inner(self) -> T
 
pub fn into_inner(self) -> T
Unwrap into inner T value.
Trait Implementations
sourceimpl<T> FromRequest for Form<T> where
    T: DeserializeOwned + 'static, 
 
impl<T> FromRequest for Form<T> where
    T: DeserializeOwned + 'static, 
See here for example of usage as an extractor.
type Future = FormExtractFut<T>
type Future = FormExtractFut<T>
Future that resolves to a Self.
sourcefn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
 
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future
Create a Self from request parts asynchronously.
sourcefn extract(req: &HttpRequest) -> Self::Future
 
fn extract(req: &HttpRequest) -> Self::Future
Create a Self from request head asynchronously. Read more
sourceimpl<T: Ord> Ord for Form<T>
 
impl<T: Ord> Ord for Form<T>
sourceimpl<T: PartialOrd> PartialOrd<Form<T>> for Form<T>
 
impl<T: PartialOrd> PartialOrd<Form<T>> for Form<T>
sourcefn partial_cmp(&self, other: &Form<T>) -> Option<Ordering>
 
fn partial_cmp(&self, other: &Form<T>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
 
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
 
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl<T: Serialize> Responder for Form<T>
 
impl<T: Serialize> Responder for Form<T>
See here for example of usage as a handler return type.
type Body = EitherBody<String, BoxBody>
sourcefn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
 
fn respond_to(self, _: &HttpRequest) -> HttpResponse<Self::Body>ⓘNotable traits for HttpResponse<BoxBody>impl Future for HttpResponse<BoxBody>    type Output = Result<Response<BoxBody>, Error>;
Convert self to HttpResponse.
sourcefn customize(self) -> CustomizeResponder<Self> where
    Self: Sized, 
 
fn customize(self) -> CustomizeResponder<Self> where
    Self: Sized, 
Wraps responder to allow alteration of its response. Read more
impl<T: Eq> Eq for Form<T>
impl<T> StructuralEq for Form<T>
impl<T> StructuralPartialEq for Form<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Form<T> where
    T: RefUnwindSafe, 
impl<T> Send for Form<T> where
    T: Send, 
impl<T> Sync for Form<T> where
    T: Sync, 
impl<T> Unpin for Form<T> where
    T: Unpin, 
impl<T> UnwindSafe for Form<T> where
    T: UnwindSafe, 
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
    T: ?Sized, 
 
impl<T> BorrowMut<T> for T where
    T: ?Sized, 
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
 
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
    Q: Eq + ?Sized,
    K: Borrow<Q> + ?Sized, 
 
impl<Q, K> Equivalent<K> for Q where
    Q: Eq + ?Sized,
    K: Borrow<Q> + ?Sized, 
sourcefn equivalent(&self, key: &K) -> bool
 
fn equivalent(&self, key: &K) -> bool
Compare self to key and return true if they are equal.
sourceimpl<T> Instrument for T
 
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
 
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
 
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
 
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
    S: Into<Dispatch>, 
 
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
    S: Into<Dispatch>, 
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
 
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more
