Trait axum::extract::FromRequest [−][src]
pub trait FromRequest<B = Body>: Sized {
type Rejection: IntoResponse;
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>>
where
'life0: 'async_trait,
Self: 'async_trait;
}
Expand description
Types that can be created from requests.
See the module docs for more details.
What is the B
type parameter?
FromRequest
is generic over the request body (the B
in
http::Request<B>
). This is to allow FromRequest
to be usable will any
type of request body. This is necessary because some middleware change the
request body, for example to add timeouts.
If you’re writing your own FromRequest
that wont be used outside your
application, and not using any middleware that changes the request body, you
can most likely use axum::body::Body
. Note this is also the default.
If you’re writing a library, thats intended for others to use, its recommended to keep the generic type parameter:
use axum::{
async_trait,
extract::{FromRequest, RequestParts},
};
struct MyExtractor;
#[async_trait]
impl<B> FromRequest<B> for MyExtractor
where
B: Send, // required by `async_trait`
{
type Rejection = http::StatusCode;
async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Self::Rejection> {
// ...
}
}
This ensures your extractor is as flexible as possible.
Associated Types
type Rejection: IntoResponse
type Rejection: IntoResponse
If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Required methods
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Perform the extraction.
Implementations on Foreign Types
type Rejection = RequestAlreadyExtracted
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = HeadersAlreadyExtracted
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = BytesRejection
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = BodyAlreadyExtracted
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<Body>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = StringRejection
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
__arg0: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<(), Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
impl<B, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T1: FromRequest<B> + Send,
T2: FromRequest<B> + Send,
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T1: FromRequest<B> + Send,
T2: FromRequest<B> + Send,
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T2: FromRequest<B> + Send,
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T2: FromRequest<B> + Send,
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T3: FromRequest<B> + Send,
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T4: FromRequest<B> + Send,
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T5: FromRequest<B> + Send,
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T6: FromRequest<B> + Send,
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T7: FromRequest<B> + Send,
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T8, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T8, T9, T10, T11, T12, T13, T14, T15, T16) where
T8: FromRequest<B> + Send,
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T9, T10, T11, T12, T13, T14, T15, T16) where
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T9, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T9, T10, T11, T12, T13, T14, T15, T16) where
T9: FromRequest<B> + Send,
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T10, T11, T12, T13, T14, T15, T16) where
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T10, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T10, T11, T12, T13, T14, T15, T16) where
T10: FromRequest<B> + Send,
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T11, T12, T13, T14, T15, T16) where
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T11, T12, T13, T14, T15, T16> FromRequest<B> for (T11, T12, T13, T14, T15, T16) where
T11: FromRequest<B> + Send,
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T12, T13, T14, T15, T16> FromRequest<B> for (T12, T13, T14, T15, T16) where
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T12, T13, T14, T15, T16> FromRequest<B> for (T12, T13, T14, T15, T16) where
T12: FromRequest<B> + Send,
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T13, T14, T15, T16> FromRequest<B> for (T13, T14, T15, T16) where
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T13, T14, T15, T16> FromRequest<B> for (T13, T14, T15, T16) where
T13: FromRequest<B> + Send,
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T14, T15, T16> FromRequest<B> for (T14, T15, T16) where
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T14, T15, T16> FromRequest<B> for (T14, T15, T16) where
T14: FromRequest<B> + Send,
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T15, T16> FromRequest<B> for (T15, T16) where
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
impl<B, T15, T16> FromRequest<B> for (T15, T16) where
T15: FromRequest<B> + Send,
T16: FromRequest<B> + Send,
B: Send,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Option<T>, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
type Rejection = Infallible
fn from_request<'life0, 'async_trait>(
req: &'life0 mut RequestParts<B>
) -> Pin<Box<dyn Future<Output = Result<Self, Self::Rejection>> + Send + 'async_trait>> where
'life0: 'async_trait,
Self: 'async_trait,
Implementors
impl<B> FromRequest<B> for BodyStream where
B: HttpBody + Send + 'static,
B::Data: Into<Bytes>,
B::Error: Into<BoxError>,
impl<B> FromRequest<B> for Multipart where
B: Body<Data = Bytes> + Default + Unpin + Send + 'static,
B::Error: Into<BoxError> + 'static,
multipart
only.impl<B> FromRequest<B> for WebSocketUpgrade where
B: Send,
ws
only.impl<T, B> FromRequest<B> for Json<T> where
T: DeserializeOwned,
B: Body + Send,
B::Data: Send,
B::Error: Into<BoxError>,
impl<T, B> FromRequest<B> for Form<T> where
T: DeserializeOwned,
B: Body + Send,
B::Data: Send,
B::Error: Into<BoxError>,
impl<T, B> FromRequest<B> for TypedHeader<T> where
T: Header,
B: Send,
headers
only.