pub struct TypeMap<A: ?Sized = dyn UnsafeAny> where
A: UnsafeAnyExt, { /* 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
sourceimpl<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> where
K::Value: Any + Implements<A>,
pub fn insert<K: Key>(&mut self, val: K::Value) -> Option<K::Value> where
K::Value: Any + Implements<A>,
Insert a value into the map with a specified key type.
sourcepub fn get<K: Key>(&self) -> Option<&K::Value> where
K::Value: Any + Implements<A>,
pub fn get<K: Key>(&self) -> Option<&K::Value> where
K::Value: Any + Implements<A>,
Find a value in the map and get a reference to it.
sourcepub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value> where
K::Value: Any + Implements<A>,
pub fn get_mut<K: Key>(&mut self) -> Option<&mut K::Value> where
K::Value: Any + Implements<A>,
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> where
K::Value: Any + Implements<A>,
pub fn remove<K: Key>(&mut self) -> Option<K::Value> where
K::Value: Any + Implements<A>,
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> where
K::Value: Any + Implements<A>,
pub fn entry<'a, K: Key>(&'a mut self) -> Entry<'a, K, A> where
K::Value: Any + Implements<A>,
Get the given key’s corresponding entry in the map for in-place manipulation.
Trait Implementations
Auto Trait Implementations
impl<A: ?Sized> RefUnwindSafe for TypeMap<A> where
A: RefUnwindSafe,
impl<A: ?Sized> Send for TypeMap<A> where
A: Send,
impl<A: ?Sized> Sync for TypeMap<A> where
A: Sync,
impl<A: ?Sized> Unpin for TypeMap<A>
impl<A: ?Sized> UnwindSafe for TypeMap<A> where
A: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more