vrp_core/models/
extras.rs1use rustc_hash::FxHasher;
2use std::any::{Any, TypeId};
3use std::collections::HashMap;
4use std::hash::BuildHasherDefault;
5use std::sync::Arc;
6
7#[derive(Clone, Debug, Default)]
9pub struct Extras {
10 index: HashMap<TypeId, Arc<dyn Any + Send + Sync>, BuildHasherDefault<FxHasher>>,
11}
12
13impl Extras {
14 pub fn get_value<K: 'static, V: Send + Sync + 'static>(&self) -> Option<Arc<V>> {
16 self.index.get(&TypeId::of::<K>()).cloned().and_then(|any| any.downcast::<V>().ok())
17 }
18
19 pub fn set_value<K: 'static, V: 'static + Sync + Send>(&mut self, value: Arc<V>) {
21 self.index.insert(TypeId::of::<K>(), value);
22 }
23}