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> TypeMap<A>where
A: UnsafeAnyExt + ?Sized,
impl<A> TypeMap<A>where
A: UnsafeAnyExt + ?Sized,
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>(&mut self, val: <K as Key>::Value) -> Option<<K as Key>::Value>
pub fn insert<K>(&mut self, val: <K as Key>::Value) -> Option<<K as Key>::Value>
Insert a value into the map with a specified key type.
Sourcepub fn get<K>(&self) -> Option<&<K as Key>::Value>
pub fn get<K>(&self) -> Option<&<K as Key>::Value>
Find a value in the map and get a reference to it.
Sourcepub fn get_mut<K>(&mut self) -> Option<&mut <K as Key>::Value>
pub fn get_mut<K>(&mut self) -> Option<&mut <K as Key>::Value>
Find a value in the map and get a mutable reference to it.
Sourcepub fn contains<K>(&self) -> boolwhere
K: Key,
pub fn contains<K>(&self) -> boolwhere
K: Key,
Check if a key has an associated value stored in the map.
Sourcepub fn remove<K>(&mut self) -> Option<<K as Key>::Value>
pub fn remove<K>(&mut self) -> Option<<K as Key>::Value>
Remove a value from the map.
Returns true
if a value was removed.
Sourcepub fn entry<'a, K>(&'a mut self) -> Entry<'a, K, A>
pub fn entry<'a, K>(&'a mut self) -> Entry<'a, K, A>
Get the given key’s corresponding entry in the map for in-place manipulation.