pub struct RequestContextExt(/* private fields */);
Expand description
Wrapper type that can be injected into the dynamic extensions of a “Response”,
in order to preserve the Context
’s extensions of the Request
which was used to produce the Response.
Methods from Deref<Target = Extensions>§
Sourcepub fn insert<T: Clone + Send + Sync + 'static>(&mut self, val: T) -> Option<T>
pub fn insert<T: Clone + Send + Sync + 'static>(&mut self, val: T) -> Option<T>
Insert a type into this Extensions
.
If a extension of this type already existed, it will be returned.
Sourcepub fn maybe_insert<T: Clone + Send + Sync + 'static>(
&mut self,
val: Option<T>,
) -> Option<T>
pub fn maybe_insert<T: Clone + Send + Sync + 'static>( &mut self, val: Option<T>, ) -> Option<T>
Insert a type only into this Extensions
, if the value is Some(T)
.
See Self::insert
for more information.
Sourcepub fn extend(&mut self, other: Extensions)
pub fn extend(&mut self, other: Extensions)
Extend these extensions with another Extensions.
Sourcepub fn contains<T: Send + Sync + 'static>(&self) -> bool
pub fn contains<T: Send + Sync + 'static>(&self) -> bool
Returns true if the Extensions
contains the given type.
Sourcepub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
pub fn get<T: Send + Sync + 'static>(&self) -> Option<&T>
Get a shared reference to a type previously inserted on this Extensions
.
Sourcepub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>
pub fn get_mut<T: Send + Sync + 'static>(&mut self) -> Option<&mut T>
Get an exclusive reference to a type previously inserted on this Extensions
.
Sourcepub fn get_or_insert_with_ext<T: Clone + Send + Sync + 'static>(
&mut self,
f: impl FnOnce(&Self) -> T,
) -> &mut T
pub fn get_or_insert_with_ext<T: Clone + Send + Sync + 'static>( &mut self, f: impl FnOnce(&Self) -> T, ) -> &mut T
Inserts a value into the map computed from f
into if it is None
,
then returns an exclusive reference to the contained value.
Use the cheaper Self::get_or_insert_with
in case you do not need access to
the extensions for the creation of T
, as this function comes with
an extra cost.
Sourcepub fn get_or_insert_with<T: Send + Sync + Clone + 'static>(
&mut self,
f: impl FnOnce() -> T,
) -> &mut T
pub fn get_or_insert_with<T: Send + Sync + Clone + 'static>( &mut self, f: impl FnOnce() -> T, ) -> &mut T
Inserts a value into the map computed from f
into if it is None
,
then returns an exclusive reference to the contained value.
Sourcepub fn get_or_insert_from<T, U>(&mut self, src: U) -> &mut T
pub fn get_or_insert_from<T, U>(&mut self, src: U) -> &mut T
Inserts a value into the map computed by converting U
into T
if it is None
then returns an exclusive reference to the contained value.
Sourcepub fn get_or_insert<T: Clone + Send + Sync + 'static>(
&mut self,
fallback: T,
) -> &mut T
pub fn get_or_insert<T: Clone + Send + Sync + 'static>( &mut self, fallback: T, ) -> &mut T
Retrieves a value of type T
from the context.
If the value does not exist, the given value is inserted and an exclusive reference to it is returned.
Sourcepub fn get_or_insert_default<T: Default + Clone + Send + Sync + 'static>(
&mut self,
) -> &mut T
pub fn get_or_insert_default<T: Default + Clone + Send + Sync + 'static>( &mut self, ) -> &mut T
Get an extension or T
’s Default
.
see Extensions::get
for more details.
Trait Implementations§
Source§impl AsMut<Extensions> for RequestContextExt
impl AsMut<Extensions> for RequestContextExt
Source§fn as_mut(&mut self) -> &mut Extensions
fn as_mut(&mut self) -> &mut Extensions
Source§impl AsRef<Extensions> for RequestContextExt
impl AsRef<Extensions> for RequestContextExt
Source§fn as_ref(&self) -> &Extensions
fn as_ref(&self) -> &Extensions
Source§impl Clone for RequestContextExt
impl Clone for RequestContextExt
Source§fn clone(&self) -> RequestContextExt
fn clone(&self) -> RequestContextExt
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more