pub struct Values(/* private fields */);Expand description
Cache that can store any value.
It uses a key type to identify the value inserted to the cache. The key type
needs to implement ValueKey.
Implementations§
Source§impl Values
impl Values
Sourcepub fn set<K>(&mut self, value: K::Type)where
K: ValueKey,
pub fn set<K>(&mut self, value: K::Type)where
K: ValueKey,
Set a value for the specified key K.
Sourcepub fn get<K>(&self) -> K::Type
pub fn get<K>(&self) -> K::Type
Get the value that was stored for the specified key K.
Panics if the key was not set before.
Sourcepub fn get_ref<K>(&self) -> &K::Typewhere
K: ValueKey,
pub fn get_ref<K>(&self) -> &K::Typewhere
K: ValueKey,
Get a reference to the value that was stored for the specified key K.
Panics if the key was not set before.
Sourcepub fn get_mut<K>(&mut self) -> &mut K::Typewhere
K: ValueKey,
pub fn get_mut<K>(&mut self) -> &mut K::Typewhere
K: ValueKey,
Get a mutable reference to the value that was stored for the specified key K.
Panics if the key was not set before.
Sourcepub fn get_or_create<K>(&mut self) -> &mut K::Type
pub fn get_or_create<K>(&mut self) -> &mut K::Type
Get a mutable reference to the value that was stored for the specified key K.
If no value is available a new one is created.
Sourcepub fn get_or_create_with<K, F>(&mut self, f: F) -> &mut K::Type
pub fn get_or_create_with<K, F>(&mut self, f: F) -> &mut K::Type
Get a mutable reference to the value that was stored for the specified key K.
If no value is available a new one is created with the provided function f.