pub struct StateStorage { /* private fields */ }Expand description
Thread-safe, type-erased key-value store for sharing state between handlers.
Backed by a DashMap so reads never block writes.
Thread-safe, type-keyed store for sharing data across handlers.
Values are stored by their TypeId so each type occupies exactly one
slot. Use this for things that are global to the bot — database pools,
configuration, shared counters.
StateStorage is cheap to clone (internally Arc-backed) and reads
never block writes.
§Example
ⓘ
use rustigram_bot::state::StateStorage;
let store = StateStorage::new();
store.insert(42_u32);
store.insert(my_db_pool);
let n: u32 = store.get().unwrap(); // 42Implementations§
Trait Implementations§
Source§impl Clone for StateStorage
impl Clone for StateStorage
Source§fn clone(&self) -> StateStorage
fn clone(&self) -> StateStorage
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for StateStorage
impl Default for StateStorage
Source§fn default() -> StateStorage
fn default() -> StateStorage
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for StateStorage
impl !UnwindSafe for StateStorage
impl Freeze for StateStorage
impl Send for StateStorage
impl Sync for StateStorage
impl Unpin for StateStorage
impl UnsafeUnpin for StateStorage
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