Skip to main content

StateStoreProvider

Trait StateStoreProvider 

Source
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§

Source

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,

Get a single value by key from a store partition.

§Arguments
  • store_id - The partition identifier (typically the plugin ID)
  • key - The key to retrieve
§Returns
  • Ok(Some(value)) - The value was found
  • Ok(None) - The key doesn’t exist in the store
  • Err(e) - An error occurred
Source

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 set
  • value - The value to store
§Returns
  • Ok(()) - The value was successfully stored
  • Err(e) - An error occurred
Source

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,

Delete a single key from a store partition.

§Arguments
  • store_id - The partition identifier (typically the plugin ID)
  • key - The key to delete
§Returns
  • Ok(true) - The key existed and was deleted
  • Ok(false) - The key didn’t exist
  • Err(e) - An error occurred
Source

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 exists
  • Ok(false) - The key doesn’t exist
  • Err(e) - An error occurred
Source

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,

Get multiple values by keys from a store partition.

§Arguments
  • store_id - The partition identifier (typically the plugin ID)
  • keys - The keys to retrieve
§Returns

A HashMap mapping each found key to its value. Keys that don’t exist are simply not included in the result.

Source

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 stored
  • Err(e) - An error occurred (some values may have been stored)
Source

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,

Delete multiple keys from a store partition.

§Arguments
  • store_id - The partition identifier (typically the plugin ID)
  • keys - The keys to delete
§Returns
  • Ok(count) - The number of keys that were deleted
  • Err(e) - An error occurred (some keys may have been deleted)
Source

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,

Delete all data for a store partition.

§Arguments
  • store_id - The partition identifier to clear
§Returns
  • Ok(count) - The number of keys that were deleted
  • Err(e) - An error occurred
Source

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,

List all keys in a store partition.

§Arguments
  • store_id - The partition identifier
§Returns

A vector of all keys in the store partition

Source

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,

Check if a store partition exists and has any data.

§Arguments
  • store_id - The partition identifier to check
§Returns
  • Ok(true) - The store partition exists and has at least one key
  • Ok(false) - The store partition doesn’t exist or is empty
  • Err(e) - An error occurred while checking
Source

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,

Get the number of keys in a store partition.

§Arguments
  • store_id - The partition identifier
§Returns
  • Ok(count) - The number of keys in the store
  • Err(e) - An error occurred

Provided Methods§

Source

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 successfully
  • Err(e) - An error occurred during sync

Implementors§