Struct Form

#[must_use]
pub struct Form<T>(pub T);

URL encoded extractor and response.

As extractor

If used as an extractor, Form will deserialize form data from the request, specifically:

This matches how HTML forms are sent by browsers by default. In both cases, the inner type T must implement serde::Deserialize.

⚠️ Since parsing form data might require consuming the request body, the Form extractor must be last if there are multiple extractors in a handler. See "the order of extractors"

use axum::Form;
use serde::Deserialize;

#[derive(Deserialize)]
struct SignUp {
    username: String,
    password: String,
}

async fn accept_form(Form(sign_up): Form<SignUp>) {
    // ...
}

As response

Form can also be used to encode any type that implements serde::Serialize as application/x-www-form-urlencoded

use axum::Form;
use serde::Serialize;

#[derive(Serialize)]
struct Payload {
    value: String,
}

async fn handler() -> Form<Payload> {
    Form(Payload { value: "foo".to_owned() })
}

Fields

0: T

Trait Implementations

impl<T> Deref for Form<T>

type Target = T;
fn deref(&self) -> &Self::Target

impl<T> DerefMut for Form<T>

fn deref_mut(&mut self) -> &mut Self::Target

impl<T> IntoResponse for Form<T> where T: Serialize,

fn into_response(self) -> Response

impl<T, S> FromRequest<S> for Form<T> where T: DeserializeOwned, S: Send + Sync,

type Rejection = FormRejection;
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection>

impl<T: Clone> Clone for Form<T>

fn clone(&self) -> Self

impl<T: Copy> Copy for Form<T>

impl<T: Debug> Debug for Form<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: Default> Default for Form<T>

fn default() -> Self

Auto Trait Implementations

impl<T> Freeze for Form<T> where T: Freeze,

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> UnsafeUnpin for Form<T> where T: UnsafeUnpin,

impl<T> UnwindSafe for Form<T> where T: UnwindSafe,

Blanket Implementations

impl<H, T> HandlerWithoutStateExt<T> for Form<T> where H: Handler<T, ()>,

fn into_service(self) -> HandlerService<H, T, ()>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service_with_connect_info<C>(self) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

impl<P, T> Receiver for Form<T> where P: Deref<Target = T> + ?Sized, T: ?Sized,

type Target = T;

impl<R> Rng for Form<T> where R: RngCore + ?Sized,

impl<R> TryCryptoRng for Form<T> where R: CryptoRng + ?Sized,

impl<R> TryRngCore for Form<T> where R: RngCore + ?Sized,

type Error = never;
fn try_next_u32(&mut self) -> Result<u32, <R as TryRngCore>::Error>
fn try_next_u64(&mut self) -> Result<u64, <R as TryRngCore>::Error>
fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), <R as TryRngCore>::Error>

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for Form<T> where ST: ?Sized, DT: ?Sized,

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for Form<T> where ST: ?Sized, DT: ?Sized,

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for Form<T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> CryptoRng for Form<T> where T: DerefMut, <T as Deref>::Target: CryptoRng,

impl<T> From<T> for Form<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FromRef<T> for Form<T> where T: Clone,

fn from_ref(input: &T) -> T

impl<T> Instrument for Form<T>

impl<T> Read<Exclusive, BecauseExclusive> for Form<T> where T: ?Sized,

impl<T> RngCore for Form<T> where T: DerefMut, <T as Deref>::Target: RngCore,

fn next_u32(&mut self) -> u32
fn next_u64(&mut self) -> u64
fn fill_bytes(&mut self, dst: &mut [u8])

impl<T> Same for Form<T>

type Output = T;

impl<T> ToOwned for Form<T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T> WithSubscriber for Form<T>

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

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

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

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

impl<V, T> VZip<V> for Form<T> where V: MultiLane<T>,

fn vzip(self) -> V