pub trait StateStoreProvider: Send + Sync {
// Required methods
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Option<Vec<u8>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn contains_key<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn get_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<HashMap<String, Vec<u8>>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn set_many<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
entries: &'life2 [(&'life3 str, &'life4 [u8])],
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait;
fn delete_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait;
fn clear_store<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn list_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Vec<String>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn store_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn key_count<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn sync<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Trait defining the interface for state store providers.
State store providers allow plugins (Sources, BootstrapProviders, and Reactions) to persist runtime state that survives restarts of DrasiLib.
§Thread Safety
Implementations must be thread-safe and support concurrent access from multiple plugins.
§Partitioning
The state store uses store_id to partition data between different plugins.
Each plugin should use a unique store_id (typically the plugin’s ID) to
avoid conflicts with other plugins.
§Example Implementation
use drasi_lib::StateStoreProvider;
use async_trait::async_trait;
pub struct MyStateStore {
// implementation fields
}
#[async_trait]
impl StateStoreProvider for MyStateStore {
async fn get(&self, store_id: &str, key: &str) -> StateStoreResult<Option<Vec<u8>>> {
// implementation
}
async fn set(&self, store_id: &str, key: &str, value: Vec<u8>) -> StateStoreResult<()> {
// implementation
}
async fn delete(&self, store_id: &str, key: &str) -> StateStoreResult<bool> {
// implementation
}
// ... implement other methods
}Required Methods§
Sourcefn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Option<Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
value: Vec<u8>,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Set a single value by key in a store partition.
The state must be persisted before this method returns.
§Arguments
store_id- The partition identifier (typically the plugin ID)key- The key to setvalue- The value to store
§Returns
Ok(())- The value was successfully storedErr(e)- An error occurred
Sourcefn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sourcefn contains_key<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn contains_key<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Check if a key exists in a store partition without retrieving its value.
This is more efficient than get() when you only need to check existence,
especially for large values.
§Arguments
store_id- The partition identifier (typically the plugin ID)key- The key to check
§Returns
Ok(true)- The key existsOk(false)- The key doesn’t existErr(e)- An error occurred
Sourcefn get_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<HashMap<String, Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn get_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<HashMap<String, Vec<u8>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Sourcefn set_many<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
entries: &'life2 [(&'life3 str, &'life4 [u8])],
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
fn set_many<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
entries: &'life2 [(&'life3 str, &'life4 [u8])],
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
'life4: 'async_trait,
Set multiple key-value pairs in a store partition.
All values must be persisted before this method returns.
§Arguments
store_id- The partition identifier (typically the plugin ID)entries- The key-value pairs to store
§Returns
Ok(())- All values were successfully storedErr(e)- An error occurred (some values may have been stored)
Sourcefn delete_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn delete_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
keys: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Sourcefn clear_store<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn clear_store<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<usize>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn list_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn list_keys<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Sourcefn store_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn store_exists<'life0, 'life1, 'async_trait>(
&'life0 self,
store_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = StateStoreResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Provided Methods§
Sourcefn sync<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn sync<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = StateStoreResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Force pending writes to persistent storage.
For in-memory stores, this is a no-op. For persistent stores, this ensures all data is durably written to disk.
§Returns
Ok(())- Sync completed successfullyErr(e)- An error occurred during sync