pub struct State { /* private fields */ }Expand description
Application state container for type-safe dependency injection and data sharing.
State provides a thread-safe way to store and retrieve shared data across
the entire application. It uses TypeId as keys to ensure type safety.
Implementations§
Source§impl State
impl State
pub fn new() -> Self
Sourcepub fn get<T>(&self) -> Result<T, DependencyInjectionError>
pub fn get<T>(&self) -> Result<T, DependencyInjectionError>
Extract a clone of the stored value of type T from the state.
Sourcepub fn borrow<T>(&self) -> Result<Arc<T>, DependencyInjectionError>
pub fn borrow<T>(&self) -> Result<Arc<T>, DependencyInjectionError>
Borrow an Arc to the stored value of type T from the state.
This returns an Arc<T> without cloning the underlying value.
pub fn insert<T: Send + Sync + 'static>(&self, state: T)
pub fn insert_instance( &self, type_id: TypeId, instance: Arc<dyn Any + Send + Sync>, )
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for State
impl !UnwindSafe for State
impl Freeze for State
impl Send for State
impl Sync for State
impl Unpin for State
impl UnsafeUnpin for State
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