pub struct TypedStateManager<S>where
S: AgentState,{ /* private fields */ }Expand description
A typed state manager for custom state types.
This provides the same functionality as StateManager but works with
strongly-typed state objects that implement AgentState.
§Example
use ag_ui_core::state::TypedStateManager;
use ag_ui_core::AgentState;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
struct AppState {
count: u32,
user: Option<String>,
}
impl AgentState for AppState {}
let mut manager = TypedStateManager::new(AppState { count: 0, user: None });
let delta = manager.update(AppState { count: 1, user: None });
assert!(delta.is_some());
assert_eq!(manager.current().count, 1);Implementations§
Source§impl<S> TypedStateManager<S>where
S: AgentState + PartialEq,
impl<S> TypedStateManager<S>where
S: AgentState + PartialEq,
Sourcepub fn new(initial: S) -> TypedStateManager<S>
pub fn new(initial: S) -> TypedStateManager<S>
Creates a new typed state manager with the given initial state.
Sourcepub fn update(&mut self, new_state: S) -> Option<Patch>
pub fn update(&mut self, new_state: S) -> Option<Patch>
Updates the state and returns the delta patch if there were changes.
Returns None if the new state is identical to the current state.
Trait Implementations§
Source§impl<S> Clone for TypedStateManager<S>where
S: Clone + AgentState,
impl<S> Clone for TypedStateManager<S>where
S: Clone + AgentState,
Source§fn clone(&self) -> TypedStateManager<S>
fn clone(&self) -> TypedStateManager<S>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<S> Debug for TypedStateManager<S>where
S: Debug + AgentState,
impl<S> Debug for TypedStateManager<S>where
S: Debug + AgentState,
Source§impl<S> Default for TypedStateManager<S>where
S: AgentState + PartialEq,
impl<S> Default for TypedStateManager<S>where
S: AgentState + PartialEq,
Source§fn default() -> TypedStateManager<S>
fn default() -> TypedStateManager<S>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<S> Freeze for TypedStateManager<S>where
S: Freeze,
impl<S> RefUnwindSafe for TypedStateManager<S>where
S: RefUnwindSafe,
impl<S> Send for TypedStateManager<S>
impl<S> Sync for TypedStateManager<S>
impl<S> Unpin for TypedStateManager<S>where
S: Unpin,
impl<S> UnsafeUnpin for TypedStateManager<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for TypedStateManager<S>where
S: UnwindSafe,
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