pub struct Extensions { /* private fields */ }Expand description
A type map of protocol extensions.
Extensions can be used by Request and Response to store
extra data derived from the underlying protocol.
Implementations§
Source§impl Extensions
impl 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 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 Extensions
impl Clone for Extensions
Source§fn clone(&self) -> Extensions
fn clone(&self) -> Extensions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more