pub struct AppState<C: ConfigProvider> { /* private fields */ }Expand description
Thread-safe shared application state.
Generic over C: ConfigProvider so that any domain can use it
with their own configuration type. The configuration is wrapped
in an Arc for cheap cloning and thread-safe sharing.
§Type Parameters
C— The domain-specific configuration provider
§Thread Safety
AppState is Clone, Send, and Sync. Cloning is cheap (Arc clone).
Multiple request handlers can share the same state concurrently.
Implementations§
Source§impl<C: ConfigProvider> AppState<C>
impl<C: ConfigProvider> AppState<C>
Sourcepub fn from_arc(config: Arc<C>) -> Self
pub fn from_arc(config: Arc<C>) -> Self
Create AppState from an existing Arc-wrapped configuration.
Useful when the configuration is already shared elsewhere.
§Arguments
config— Arc-wrapped configuration
Sourcepub fn config_arc(&self) -> Arc<C>
pub fn config_arc(&self) -> Arc<C>
Get a cloneable handle to the configuration.
Returns an Arc<C> that can be passed to subsystems that need
their own owned reference to the configuration.
§Example
let config_arc = state.config_arc();
// Pass config_arc to another subsystemSourcepub fn project_name(&self) -> &str
pub fn project_name(&self) -> &str
Get the project name from the configuration.
Convenience method equivalent to state.config().project_name().
Trait Implementations§
Source§impl<C: ConfigProvider> Clone for AppState<C>
impl<C: ConfigProvider> Clone for AppState<C>
impl<C: ConfigProvider> Send for AppState<C>
impl<C: ConfigProvider> Sync for AppState<C>
Auto Trait Implementations§
impl<C> Freeze for AppState<C>
impl<C> RefUnwindSafe for AppState<C>where
C: RefUnwindSafe,
impl<C> Unpin for AppState<C>
impl<C> UnsafeUnpin for AppState<C>
impl<C> UnwindSafe for AppState<C>where
C: RefUnwindSafe,
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