Struct axum_core::extract::RequestParts
source · [−]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
sourceimpl<B> RequestParts<B>
impl<B> RequestParts<B>
sourcepub fn new(req: Request<B>) -> Self
pub fn new(req: Request<B>) -> Self
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
.
sourcepub async fn extract<E: FromRequest<B>>(&mut self) -> Result<E, E::Rejection>
pub async fn extract<E: FromRequest<B>>(&mut self) -> Result<E, E::Rejection>
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!()
}
}
sourcepub fn try_into_request(self) -> Result<Request<B>, BodyAlreadyExtracted>
pub fn try_into_request(self) -> Result<Request<B>, BodyAlreadyExtracted>
sourcepub fn method_mut(&mut self) -> &mut Method
pub fn method_mut(&mut self) -> &mut Method
Gets a mutable reference to the request method.
sourcepub fn version_mut(&mut self) -> &mut Version
pub fn version_mut(&mut self) -> &mut Version
Gets a mutable reference to the request HTTP version.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap
pub fn headers_mut(&mut self) -> &mut HeaderMap
Gets a mutable reference to the request headers.
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
Gets a reference to the request extensions.
sourcepub fn extensions_mut(&mut self) -> &mut Extensions
pub fn extensions_mut(&mut self) -> &mut Extensions
Gets a mutable reference to the request extensions.
sourcepub fn body(&self) -> Option<&B>
pub fn body(&self) -> Option<&B>
Gets a reference to the request body.
Returns None
if the body has been taken by another extractor.