pub struct Context { /* private fields */ }Expand description
A map that can store values of any type specified by AnyValueSpec.
Implementations§
Source§impl Context
impl Context
Sourcepub fn initialize(&mut self, reg: &ContextKeyRegistry)
pub fn initialize(&mut self, reg: &ContextKeyRegistry)
Initializes the context with a given ContextKeyRegistry.
Sourcepub fn insert<T: AnyValueSpec>(&mut self, key: ContextKey<T>, value: T::Item)
pub fn insert<T: AnyValueSpec>(&mut self, key: ContextKey<T>, value: T::Item)
Inserts a value into the context.
Sourcepub fn get<T: AnyValueSpec>(&self, key: ContextKey<T>) -> Option<&T::Item>
pub fn get<T: AnyValueSpec>(&self, key: ContextKey<T>) -> Option<&T::Item>
Gets a reference to a value from the context.
Sourcepub fn get_or_insert<T: AnyValueSpec>(
&mut self,
key: ContextKey<T>,
default: impl FnOnce() -> T::Item,
) -> &T::Item
pub fn get_or_insert<T: AnyValueSpec>( &mut self, key: ContextKey<T>, default: impl FnOnce() -> T::Item, ) -> &T::Item
Gets or inserts a value in the context. If the key does not exist, inserts the default value and returns a reference to it. Otherwise, returns a reference to the existing value.
Sourcepub fn get_mut<T: AnyValueSpec>(
&mut self,
key: ContextKey<T>,
) -> Option<&mut T::Item>
pub fn get_mut<T: AnyValueSpec>( &mut self, key: ContextKey<T>, ) -> Option<&mut T::Item>
Gets a mutable reference to a value from the context.
Sourcepub fn get_or_insert_mut<T: AnyValueSpec>(
&mut self,
key: ContextKey<T>,
default: impl FnOnce() -> T::Item,
) -> &mut T::Item
pub fn get_or_insert_mut<T: AnyValueSpec>( &mut self, key: ContextKey<T>, default: impl FnOnce() -> T::Item, ) -> &mut T::Item
Gets or inserts a mutable reference to a value in the context. If the key does not exist, inserts the default value and returns a mutable reference to it. Otherwise, returns a mutable reference to the existing value.
Sourcepub fn remove<T: AnyValueSpec>(&mut self, key: ContextKey<T>) -> Option<T::Item>
pub fn remove<T: AnyValueSpec>(&mut self, key: ContextKey<T>) -> Option<T::Item>
Removes a value from the context.
If the key does not exist, returns None.
Otherwise, returns the removed value.