Skip to main content

StateStorage

Trait StateStorage 

Source
pub trait StateStorage:
    Send
    + Sync
    + 'static {
    // Required methods
    fn get_state<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
    ) -> Pin<Box<dyn Future<Output = Result<Option<String>, StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn set_state<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
        state: String,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear_state<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn get_data<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: StateKey,
        field: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set_data<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: StateKey,
        field: &'life1 str,
        value: Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_all_data<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
    ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear_data<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn clear_all<'life0, 'async_trait>(
        &'life0 self,
        key: StateKey,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Persistent storage backend for FSM state.

All methods are async and return Result<_, StorageError>. Implement this trait to add custom backends (database, Redis, etc.).

Built-in implementations:

  • MemoryStorage - in-process DashMap, zero setup, no persistence.

Required Methods§

Source

fn get_state<'life0, 'async_trait>( &'life0 self, key: StateKey, ) -> Pin<Box<dyn Future<Output = Result<Option<String>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return the current state key for this slot, or None if no state is set.

Source

fn set_state<'life0, 'async_trait>( &'life0 self, key: StateKey, state: String, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Persist a new state. Overwrites any previously set state.

Source

fn clear_state<'life0, 'async_trait>( &'life0 self, key: StateKey, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear the state for this slot. Data is NOT cleared.

Source

fn get_data<'life0, 'life1, 'async_trait>( &'life0 self, key: StateKey, field: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Retrieve a single data field as a raw JSON value.

Source

fn set_data<'life0, 'life1, 'async_trait>( &'life0 self, key: StateKey, field: &'life1 str, value: Value, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Persist a single data field as a raw JSON value.

Source

fn get_all_data<'life0, 'async_trait>( &'life0 self, key: StateKey, ) -> Pin<Box<dyn Future<Output = Result<HashMap<String, Value>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Return all data fields stored for this slot.

Source

fn clear_data<'life0, 'async_trait>( &'life0 self, key: StateKey, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Remove all data fields for this slot. State is NOT cleared.

Source

fn clear_all<'life0, 'async_trait>( &'life0 self, key: StateKey, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Clear both state and all data for this slot (full reset).

Implementors§