pub struct StateMap { /* private fields */ }Expand description
A type-keyed registry holding at most one shared value per type — a minimal dependency-injection container.
Each value is keyed by its TypeId and stored behind an Arc, so reads
hand out cheap shared handles. This backs AppBuilder::state and the
State extractor; you rarely construct one directly.
use churust_core::StateMap;
let mut state = StateMap::new();
state.insert(42u32);
state.insert(String::from("hi"));
assert_eq!(*state.get::<u32>().unwrap(), 42);
assert_eq!(state.get::<String>().unwrap().as_str(), "hi");
assert!(state.get::<bool>().is_none());Implementations§
Source§impl StateMap
impl StateMap
Sourcepub fn new() -> Self
pub fn new() -> Self
Create an empty registry. Equivalent to StateMap::default.
use churust_core::StateMap;
assert!(StateMap::new().get::<u32>().is_none());Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for StateMap
impl !UnwindSafe for StateMap
impl Freeze for StateMap
impl Send for StateMap
impl Sync for StateMap
impl Unpin for StateMap
impl UnsafeUnpin for StateMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more