use std::any::TypeId; use std::collections::HashMap; /// Base typemap used for implementation but not elsewhere /// Each other typemap is just a newtype of this base type with /// additional implementation. #[doc(hidden)] #[derive(Debug)] pub(crate) struct TypeIndexedMap(pub(crate) HashMap); impl Default for TypeIndexedMap { fn default() -> Self { Self(HashMap::default()) } } impl TypeIndexedMap { #[inline] pub fn new() -> Self { Self::default() } #[inline] pub fn insert(&mut self, value: T) { self.0.insert(TypeId::of::(), value); } #[inline] pub fn get(&self) -> Option<&T> { self.0.get(&TypeId::of::()) } #[inline] pub fn get_mut(&mut self) -> Option<&mut T> { self.0.get_mut(&TypeId::of::()) } #[inline] pub fn remove(&mut self) -> Option { self.0.remove(&TypeId::of::()) } #[inline] pub fn contains_key(&self) -> bool { self.0.contains_key(&TypeId::of::()) } }