-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor dimensions to avoid using string as a key
- Loading branch information
1 parent
5afa552
commit 7282132
Showing
61 changed files
with
434 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use hashbrown::HashMap; | ||
use rustc_hash::FxHasher; | ||
use std::any::{Any, TypeId}; | ||
use std::hash::BuildHasherDefault; | ||
use std::sync::Arc; | ||
|
||
/// Multiple named dimensions which can contain anything: | ||
/// * unit of measure, e.g. volume, mass, size, etc. | ||
/// * set of skills | ||
/// * tag. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct Dimensions { | ||
index: HashMap<TypeId, Arc<dyn Any + Send + Sync>, BuildHasherDefault<FxHasher>>, | ||
} | ||
|
||
impl Dimensions { | ||
/// Gets a value using type provided. | ||
pub fn get_value<K: 'static, V: 'static>(&self) -> Option<&V> { | ||
self.index.get(&TypeId::of::<K>()).and_then(|any| any.downcast_ref::<V>()) | ||
} | ||
|
||
/// Sets the value using type provided. | ||
pub fn set_value<K: 'static, V: 'static + Sync + Send>(&mut self, value: V) { | ||
self.index.insert(TypeId::of::<K>(), Arc::new(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
//! Common models. | ||
mod dimens; | ||
pub use self::dimens::*; | ||
|
||
mod domain; | ||
pub use self::domain::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.