alibi_core/plugin/
extensions.rs1use super::*;
2#[derive(Clone, Default)]
7pub struct ContextExtensions(HashMap<TypeId, Arc<dyn Any + Send + Sync>>);
8
9impl ContextExtensions {
10 pub fn insert<T: Any + Send + Sync>(&mut self, value: T) {
11 drop(self.0.insert(TypeId::of::<T>(), Arc::new(value)));
12 }
13
14 #[must_use]
15 pub fn get<T: Any + Send + Sync>(&self) -> Option<Arc<T>> {
16 Arc::clone(self.0.get(&TypeId::of::<T>())?).downcast().ok()
17 }
18}
19
20impl std::fmt::Debug for ContextExtensions {
21 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22 f.debug_struct("ContextExtensions").finish_non_exhaustive()
23 }
24}