pub struct StateContext {
pub current_state: String,
/* private fields */
}Expand description
The FSM context injected into state-matched handlers.
Provides typed access to state transitions and arbitrary key-value data associated with the current conversation slot.
Fields§
§current_state: StringThe state key that matched this handler, provided as context.
Implementations§
Source§impl StateContext
impl StateContext
Sourcepub fn new(
storage: Arc<dyn StateStorage>,
key: StateKey,
current_state: String,
) -> Self
pub fn new( storage: Arc<dyn StateStorage>, key: StateKey, current_state: String, ) -> Self
Construct a new StateContext. Called internally by the dispatcher.
Sourcepub async fn transition(
&self,
new_state: impl FsmState,
) -> Result<(), StorageError>
pub async fn transition( &self, new_state: impl FsmState, ) -> Result<(), StorageError>
Transition to a new state. Overwrites the current state.
Sourcepub async fn clear_state(&self) -> Result<(), StorageError>
pub async fn clear_state(&self) -> Result<(), StorageError>
Clear the current state (set to None). Leaves data intact.
Sourcepub async fn set_data<T: Serialize>(
&self,
field: &str,
value: T,
) -> Result<(), StorageError>
pub async fn set_data<T: Serialize>( &self, field: &str, value: T, ) -> Result<(), StorageError>
Set a typed data value for field. The value is serialized to JSON.
Sourcepub async fn get_data<T: DeserializeOwned>(
&self,
field: &str,
) -> Result<Option<T>, StorageError>
pub async fn get_data<T: DeserializeOwned>( &self, field: &str, ) -> Result<Option<T>, StorageError>
Get a typed data value for field. Returns None if not set.
Sourcepub async fn get_all_data(&self) -> Result<HashMap<String, Value>, StorageError>
pub async fn get_all_data(&self) -> Result<HashMap<String, Value>, StorageError>
Return all data fields as a raw JSON map.
Sourcepub async fn clear_data(&self) -> Result<(), StorageError>
pub async fn clear_data(&self) -> Result<(), StorageError>
Remove all data fields. State is unchanged.
Sourcepub async fn clear_all(&self) -> Result<(), StorageError>
pub async fn clear_all(&self) -> Result<(), StorageError>
Reset both state and all data (full conversation reset).
Trait Implementations§
Source§impl Clone for StateContext
impl Clone for StateContext
Source§fn clone(&self) -> StateContext
fn clone(&self) -> StateContext
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 moreAuto Trait Implementations§
impl Freeze for StateContext
impl !RefUnwindSafe for StateContext
impl Send for StateContext
impl Sync for StateContext
impl Unpin for StateContext
impl UnsafeUnpin for StateContext
impl !UnwindSafe for StateContext
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