FromRequest

Trait FromRequest 

Source
pub trait FromRequest<B = Body, M = ViaRequest>: Sized {
    type Rejection: IntoResponse;

    // Required method
    fn from_request(
        cx: &mut ServerContext,
        parts: Parts,
        body: B,
    ) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
}
Available on crate feature server only.
Expand description

Extract a type from Request with its ServerContext

This trait is used for handlers, which can extract something from ServerContext and Request.

FromRequest will consume Request, so it can only be used once in a handler. If your extractor does not need to consume Request, please use FromContext instead.

Required Associated Types§

Source

type Rejection: IntoResponse

If the extractor fails, it will return this Rejection type.

The Rejection should implement IntoResponse. If extractor fails in handler, the rejection will be converted into a Response and returned.

Required Methods§

Source

fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> impl Future<Output = Result<Self, Self::Rejection>> + Send

Extract the type from request.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<B> FromRequest<B> for String
where B: Body + Send, B::Data: Send, B::Error: Send,

Source§

type Rejection = ExtractBodyError

Source§

async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Source§

impl<B> FromRequest<B> for Vec<u8>
where B: Body + Send, B::Data: Send, B::Error: Send,

Source§

type Rejection = ExtractBodyError

Source§

async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Source§

impl<B> FromRequest<B> for Bytes
where B: Body + Send, B::Data: Send, B::Error: Send,

Source§

type Rejection = ExtractBodyError

Source§

async fn from_request( _: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Source§

impl<B> FromRequest<B> for FastStr
where B: Body + Send, B::Data: Send, B::Error: Send,

Source§

type Rejection = ExtractBodyError

Source§

async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Source§

impl<B, T> FromRequest<B> for Option<T>
where B: Send, T: FromRequest<B, ViaRequest> + Sync,

Source§

type Rejection = Infallible

Source§

async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Source§

impl<B, T> FromRequest<B> for Result<T, T::Rejection>
where B: Send, T: FromRequest<B, ViaRequest> + Sync,

Source§

type Rejection = Infallible

Source§

async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>

Implementors§

Source§

impl FromRequest for Multipart

Available on crate feature multipart only.
Source§

impl<B> FromRequest<B> for Request<B>
where B: Send,

Source§

impl<B, T> FromRequest<B> for Form<T>
where B: Body + Send, B::Data: Send, B::Error: Send, T: DeserializeOwned,

Available on crate feature form only.
Source§

impl<B, T> FromRequest<B> for Json<T>
where B: Body + Send, B::Data: Send, B::Error: Send, T: DeserializeOwned,

Available on crate feature json only.
Source§

impl<B, T> FromRequest<B> for MaybeInvalid<T>
where B: Body + Send, B::Data: Send, B::Error: Send,