pub struct RequestParts<B> { /* private fields */ }
Expand description

The type used with FromRequest to extract data from requests.

Has several convenience methods for getting owned parts of the request.

Implementations

Create a new RequestParts.

You generally shouldn’t need to construct this type yourself, unless using extractors outside of axum for example to implement a tower::Service.

Apply an extractor to this RequestParts.

req.extract::<Extractor>() is equivalent to Extractor::from_request(req). This function simply exists as a convenience.

Example

use std::convert::Infallible;

use async_trait::async_trait;
use axum::extract::{FromRequest, RequestParts};
use http::{Method, Uri};

#[async_trait]
impl<B: Send> FromRequest<B> for MyExtractor {
    type Rejection = Infallible;

    async fn from_request(req: &mut RequestParts<B>) -> Result<Self, Infallible> {
        let method = req.extract::<Method>().await?;
        let path = req.extract::<Uri>().await?.path().to_owned();

        todo!()
    }
}

Convert this RequestParts back into a Request.

Fails if The request body has been extracted, that is take_body has been called.

Gets a reference to the request method.

Gets a mutable reference to the request method.

Gets a reference to the request URI.

Gets a mutable reference to the request URI.

Get the request HTTP version.

Gets a mutable reference to the request HTTP version.

Gets a reference to the request headers.

Gets a mutable reference to the request headers.

Gets a reference to the request extensions.

Gets a mutable reference to the request extensions.

Gets a reference to the request body.

Returns None if the body has been taken by another extractor.

Gets a mutable reference to the request body.

Returns None if the body has been taken by another extractor.

Takes the body out of the request, leaving a None in its place.

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.