[−][src]Struct actix_web::web::ReqData
Request-local data extractor.
Request-local data is arbitrary data attached to an individual request, usually
by middleware. It can be set via extensions_mut
on HttpRequest
or ServiceRequest
.
Unlike app data, request data is dropped when the request has finished processing. This makes it useful as a kind of messaging system between middleware and request handlers. It uses the same types-as-keys storage system as app data.
Mutating Request Data
Note that since extractors must output owned data, only types that impl Clone
can use this
extractor. A clone is taken of the required request data and can, therefore, not be directly
mutated in-place. To mutate request data, continue to use HttpRequest::extensions_mut
or
re-insert the cloned data back into the extensions map. A DerefMut
impl is intentionally not
provided to make this potential foot-gun more obvious.
Example
#[derive(Debug, Clone, PartialEq)] struct FlagFromMiddleware(String); /// Use the `ReqData<T>` extractor to access request data in a handler. async fn handler( req: HttpRequest, opt_flag: Option<web::ReqData<FlagFromMiddleware>>, ) -> impl Responder { // use an optional extractor if the middleware is // not guaranteed to add this type of requests data if let Some(flag) = opt_flag { assert_eq!(&flag.into_inner(), req.extensions().get::<FlagFromMiddleware>().unwrap()); } HttpResponse::Ok() }
Implementations
impl<T: Clone + 'static> ReqData<T>
[src]
pub fn into_inner(self) -> T
[src]
Consumes the ReqData
, returning its wrapped data.
Trait Implementations
impl<T: Clone + 'static> Clone for ReqData<T>
[src]
impl<T: Debug + Clone + 'static> Debug for ReqData<T>
[src]
impl<T: Clone + 'static> Deref for ReqData<T>
[src]
impl<T: Clone + 'static> FromRequest for ReqData<T>
[src]
type Config = ()
Configuration for this extractor
type Error = Error
The associated error which can be returned.
type Future = Ready<Result<Self, Error>>
Future that resolves to a Self
pub fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future
[src]
pub fn extract(req: &HttpRequest) -> Self::Future
[src]
pub fn configure<F>(f: F) -> Self::Config where
F: FnOnce(Self::Config) -> Self::Config,
[src]
F: FnOnce(Self::Config) -> Self::Config,
Auto Trait Implementations
impl<T> RefUnwindSafe for ReqData<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for ReqData<T> where
T: Send,
T: Send,
impl<T> Sync for ReqData<T> where
T: Sync,
T: Sync,
impl<T> Unpin for ReqData<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for ReqData<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,