pub struct TypeMap { /* private fields */ }
Expand description
Type-safe store, indexed by types.
Implementations§
source§impl TypeMap
impl TypeMap
sourcepub fn contains_key<T: Type>(&self) -> bool
pub fn contains_key<T: Type>(&self) -> bool
Returns whether element is present in the map.
sourcepub fn get<T: Type>(&self) -> Option<&T>
pub fn get<T: Type>(&self) -> Option<&T>
Access element in the map, returning reference to it, if present
sourcepub fn get_raw(&self, id: &TypeId) -> Option<&Value<RawType>>
pub fn get_raw(&self, id: &TypeId) -> Option<&Value<RawType>>
Access element in the map, returning reference to it, if present
sourcepub fn get_mut<T: Type>(&mut self) -> Option<&mut T>
pub fn get_mut<T: Type>(&mut self) -> Option<&mut T>
Access element in the map, returning mutable reference to it, if present
sourcepub fn get_mut_raw(&mut self, id: &TypeId) -> Option<&mut Value<RawType>>
pub fn get_mut_raw(&mut self, id: &TypeId) -> Option<&mut Value<RawType>>
Access element in the map, returning mutable reference to it, if present
sourcepub fn get_or_default<T: Type + Default>(&mut self) -> &mut T
pub fn get_or_default<T: Type + Default>(&mut self) -> &mut T
Access element in the map, if not present, constructs it using default value.
sourcepub fn insert<T: Type>(&mut self, value: T) -> Option<Box<T>>
pub fn insert<T: Type>(&mut self, value: T) -> Option<Box<T>>
Insert element inside the map, returning heap-allocated old one if any
Note
Be careful when inserting without explicitly specifying type. Some special types like function pointers are impossible to infer as non-anonymous type. You should manually specify type when in doubt.
sourcepub fn insert_raw<T: Type>(&mut self, value: Value<T>) -> Option<Value<T>>
pub fn insert_raw<T: Type>(&mut self, value: Value<T>) -> Option<Value<T>>
Insert raw element inside the map, returning heap-allocated old one if any