pub struct TypeCache { /* private fields */ }
Expand description
The TypeCache is heavily inspired by the state
crate and the way
the Rocket framework handles global and local state. You could say
we’ve immutably borrowed some ideas. Rim-shot!
Basically, we’ve got a hash that can store different types but
only one of each type. The type id is the key, and you need to
know what type you’re asking for when you call get()
to be able
to do anything with it:
let cache = TypeCache::new();
cache.set::<String>("Hi friends".to_string());
assert_eq!(Some(&"Hi friends".to_string()), cache.get::<String>());
cache.set::<usize>(12345);
assert_eq!(Some(&12345), cache.get::<usize>());
We use this in Vial for global state as well as local request
state, however this design is flawed as the local cache shouldn’t
be forced into Send + Sync
. These two will be separated in a
future release.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TypeCache
impl !RefUnwindSafe for TypeCache
impl !Send for TypeCache
impl !Sync for TypeCache
impl Unpin for TypeCache
impl !UnwindSafe for TypeCache
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