Struct axum::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>) -> RequestParts<B>
pub fn new(req: Request<B>) -> RequestParts<B>
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>(
&mut self
) -> impl Future<Output = Result<E, <E as FromRequest<B>>::Rejection>> where
E: FromRequest<B>,
pub async fn extract<E>(
&mut self
) -> impl Future<Output = Result<E, <E as FromRequest<B>>::Rejection>> where
E: FromRequest<B>,
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(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
Gets a reference to the request headers.
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
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.
Trait Implementations
Auto Trait Implementations
impl<B> !RefUnwindSafe for RequestParts<B>
impl<B> Send for RequestParts<B> where
B: Send,
impl<B> Sync for RequestParts<B> where
B: Sync,
impl<B> Unpin for RequestParts<B> where
B: Unpin,
impl<B> !UnwindSafe for RequestParts<B>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more