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-processDashMap, zero setup, no persistence.
Required Methods§
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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_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.