pub struct TypeMap<A = dyn UnsafeAny>where
A: UnsafeAnyExt + ?Sized,{ /* private fields */ }Expand description
A map keyed by types.
Can contain one value of any type for each key type, as defined by the Assoc trait.
You usually do not need to worry about the A type parameter, but it
can be used to add bounds to the possible value types that can
be stored in this map. Usually, you are looking for ShareMap, which
is Send + Sync.
Implementations§
Source§impl<A: UnsafeAnyExt + ?Sized> TypeMap<A>
impl<A: UnsafeAnyExt + ?Sized> TypeMap<A>
Sourcepub fn custom() -> TypeMap<A>
pub fn custom() -> TypeMap<A>
Create a new, empty TypeMap.
Can be used with any A parameter; new is specialized to get around
the required type annotations when using this function.
Sourcepub fn insert<K: Key>(&mut self, val: K::Value) -> Option<K::Value>
pub fn insert<K: Key>(&mut self, val: K::Value) -> Option<K::Value>
Insert a value into the map with a specified key type.
Sourcepub fn get<K: Key>(&self) -> Option<&K::Value>
pub fn get<K: Key>(&self) -> Option<&K::Value>
Find a value in the map and get a reference to it.
Sourcepub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value>
pub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value>
Find a value in the map and get a mutable reference to it.
Sourcepub fn contains<K: Key>(&self) -> bool
pub fn contains<K: Key>(&self) -> bool
Check if a key has an associated value stored in the map.
Sourcepub fn remove<K: Key>(&mut self) -> Option<K::Value>
pub fn remove<K: Key>(&mut self) -> Option<K::Value>
Remove a value from the map.
Returns true if a value was removed.
Sourcepub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A>
pub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A>
Get the given key’s corresponding entry in the map for in-place manipulation.