pub struct ContextMap { /* private fields */ }Expand description
A type-keyed container of values.
Each registered value is stored under its TypeId, so a given type can
only be registered once per ContextMap. Used by Cx to hold both the
router-wide app context and the per-request request context; values are
retrieved within a request via app_context or request_context.
Implementations§
Source§impl ContextMap
impl ContextMap
Sourcepub fn insert<T>(&mut self, value: T) -> Option<T>
pub fn insert<T>(&mut self, value: T) -> Option<T>
Registers value under its concrete type T, returning the value
previously registered for T, if any.
A type can hold only one value at a time, so registering a type that is already present replaces it and hands back the displaced value.
Sourcepub fn get<T>(&self) -> Option<&T>
pub fn get<T>(&self) -> Option<&T>
Returns a reference to the registered value of type T, or None if
no such value has been registered.
Within a request, prefer the app_context and request_context free
functions over reaching for this directly.
Trait Implementations§
Source§impl Debug for ContextMap
impl Debug for ContextMap
Source§impl Default for ContextMap
impl Default for ContextMap
Source§fn default() -> ContextMap
fn default() -> ContextMap
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ContextMap
impl !UnwindSafe for ContextMap
impl Freeze for ContextMap
impl Send for ContextMap
impl Sync for ContextMap
impl Unpin for ContextMap
impl UnsafeUnpin for ContextMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more