pub struct StateUpdateHandle<S>{ /* private fields */ }Expand description
A handle that allows external code to update the application state without having direct access to the router.
Implementations§
Source§impl<S> StateUpdateHandle<S>
impl<S> StateUpdateHandle<S>
Sourcepub fn new(sender: Sender<Box<dyn FnOnce(&mut S) + Send + 'static>>) -> Self
pub fn new(sender: Sender<Box<dyn FnOnce(&mut S) + Send + 'static>>) -> Self
Create a new state update handle
Sourcepub async fn update<F>(&self, updater: F) -> Result<(), StateUpdateError>
pub async fn update<F>(&self, updater: F) -> Result<(), StateUpdateError>
Update the application state using a closure
This allows external components to modify the shared state safely. The update is queued and applied asynchronously by the router.
§Example
// Update a counter in the state
state_handle.update(|state: &mut MyAppState| {
state.counter += 1;
}).await?;
// Update database connection pool size
state_handle.update(|state: &mut MyAppState| {
state.config.max_db_connections = 50;
}).await?;Sourcepub fn try_update<F>(&self, updater: F) -> Result<(), StateUpdateError>
pub fn try_update<F>(&self, updater: F) -> Result<(), StateUpdateError>
Attempt to update the state without blocking
Returns an error if the update channel is full or closed.
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for StateUpdateHandle<S>
impl<S> RefUnwindSafe for StateUpdateHandle<S>
impl<S> Send for StateUpdateHandle<S>
impl<S> Sync for StateUpdateHandle<S>
impl<S> Unpin for StateUpdateHandle<S>
impl<S> UnwindSafe for StateUpdateHandle<S>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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