pub struct CowState<S: State> { /* private fields */ }Expand description
Copy-on-write state wrapper (default state wrapper)
For large states (e.g., long conversation histories), cloning the entire
state for each node spawn is expensive. CowState uses Arc to share
immutable state and only clones when modified.
This is the DEFAULT state wrapper in Juncture, not just an optimization.
Implementations§
Source§impl<S: State> CowState<S>
impl<S: State> CowState<S>
Sourcepub fn get_mut(&mut self) -> &mut Swhere
S: Clone,
pub fn get_mut(&mut self) -> &mut Swhere
S: Clone,
Get mutable access to the state, cloning the inner Arc if shared
Uses clone-on-write semantics: if the Arc reference count is greater
than one, the inner state is cloned before returning a mutable reference.
This ensures no other CowState instances are affected by mutations.
Sourcepub fn update(&mut self, changes: S::Update)
pub fn update(&mut self, changes: S::Update)
Apply an update (deferred until commit)
Note: For proper merge semantics, this implementation simply stores the latest update. The proc-macro generates more sophisticated merge logic for complex update types.
Sourcepub fn try_commit(self) -> Result<Arc<S>, InvalidUpdateError>
pub fn try_commit(self) -> Result<Arc<S>, InvalidUpdateError>
Commit updates and return new shared state, propagating reducer errors
Unlike commit(), this method returns a structured error when reducer
constraints are violated (e.g., multiple writers on a replace channel).
§Errors
Returns InvalidUpdateError if the update violates reducer constraints.