pub struct SharedState(/* private fields */);Expand description
A cheaply-cloneable handle to a tool’s shared key-value state store.
ToolContext keeps its state behind this handle so multiple contexts
(e.g. successive tool calls within the same agent turn) can read and write
the same underlying store. Clone it and hand it to another context via
ToolContext::with_shared_state.
The concrete lock and map types are an implementation detail — they differ
between std and no_std builds — so they are deliberately not exposed.
Implementations§
Sourcepub fn get_state(&self, key: &str, default: Value) -> Value
pub fn get_state(&self, key: &str, default: Value) -> Value
Retrieve a value from the shared state, returning default if the key
is absent or the lock is poisoned.
Sourcepub fn remove_state(&self, key: &str) -> bool
pub fn remove_state(&self, key: &str) -> bool
Remove a value from the shared state by key, returning true if it was present.
Sourcepub fn clear_state(&self)
pub fn clear_state(&self)
Clear all entries from the shared state.
Trait Implementations§
Source§fn clone(&self) -> SharedState
fn clone(&self) -> SharedState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
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