use std::{any::Any, any::TypeId, collections::HashMap, sync::Arc};
use foldhash::fast::RandomState;
#[derive(Clone)]
pub(crate) struct Extensions {
pub(crate) map: HashMap<TypeId, Arc<dyn Any + Sync + Send>, RandomState>,
}
impl Default for Extensions {
fn default() -> Self {
Extensions {
map: HashMap::with_capacity_and_hasher(0, RandomState::default()),
}
}
}
impl Extensions {
pub(crate) fn insert<T: Sync + Send + 'static>(&mut self, val: T) {
self.map.insert(TypeId::of::<T>(), Arc::new(val));
}
pub(crate) fn get<T: 'static>(&self) -> Option<&T> {
self.map
.get(&TypeId::of::<T>())
.and_then(|boxed| boxed.downcast_ref())
}
}