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
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.
§Errors
Returns an error if no value of type T has been registered in the
state. This usually indicates that the dependency was never inserted or
was expected to be provided by a module/provider that was not registered.
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.
§Errors
Returns an error if no value of type T has been registered in the
state or if the stored value cannot be downcast back to T.
pub fn insert<T: Send + Sync + 'static>(&self, state: T)
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