vrp_core/models/common/
dimens.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)]
12pub struct Dimensions {
13 index: HashMap<TypeId, Arc<dyn Any + Send + Sync>, BuildHasherDefault<FxHasher>>,
14}
15
16impl Dimensions {
17 pub fn get_value<K: 'static, V: 'static>(&self) -> Option<&V> {
19 self.index.get(&TypeId::of::<K>()).and_then(|any| any.downcast_ref::<V>())
20 }
21
22 pub fn set_value<K: 'static, V: 'static + Sync + Send>(&mut self, value: V) {
24 self.index.insert(TypeId::of::<K>(), Arc::new(value));
25 }
26}