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§
Sourcetype Rejection: IntoResponse
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§
Sourcefn from_request(
cx: &mut ServerContext,
parts: Parts,
body: B,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send
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
impl<B> FromRequest<B> for String
type Rejection = ExtractBodyError
async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>
Source§impl<B> FromRequest<B> for Vec<u8>
impl<B> FromRequest<B> for Vec<u8>
type Rejection = ExtractBodyError
async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>
Source§impl<B> FromRequest<B> for Bytes
impl<B> FromRequest<B> for Bytes
type Rejection = ExtractBodyError
async fn from_request( _: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>
Source§impl<B> FromRequest<B> for FastStr
impl<B> FromRequest<B> for FastStr
type Rejection = ExtractBodyError
async fn from_request( cx: &mut ServerContext, parts: Parts, body: B, ) -> Result<Self, Self::Rejection>
Source§impl<B, T> FromRequest<B> for Option<T>
impl<B, T> FromRequest<B> for Option<T>
type Rejection = Infallible
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>
impl<B, T> FromRequest<B> for Result<T, T::Rejection>
type Rejection = Infallible
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.
impl FromRequest for Multipart
Available on crate feature
multipart only.Source§impl<B> FromRequest<B> for Request<B>where
B: Send,
impl<B> FromRequest<B> for Request<B>where
B: Send,
type Rejection = Infallible
Source§impl<B, T> FromRequest<B> for Form<T>
Available on crate feature form only.
impl<B, T> FromRequest<B> for Form<T>
Available on crate feature
form only.type Rejection = ExtractBodyError
Source§impl<B, T> FromRequest<B> for Json<T>
Available on crate feature json only.
impl<B, T> FromRequest<B> for Json<T>
Available on crate feature
json only.