Skip to main content

Store

Trait Store 

Source
pub trait Store: Send + Sync {
    // Required methods
    fn initialize(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
    fn get(
        &self,
        key: &str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StoreError>> + Send + '_>>;
    fn list(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<StoreModel>, StoreError>> + Send + '_>>;
    fn set(
        &self,
        key: &str,
        value: Value,
        ttl: Option<u64>,
    ) -> Pin<Box<dyn Future<Output = Result<Option<StoreModel>, StoreError>> + Send + '_>>;
    fn remove(
        &self,
        key: &str,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
    fn remove_many(
        &self,
        keys: &[&str],
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
    fn clear(
        &self,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
}

Required Methods§

Source

fn initialize( &self, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>

Initializes the storage backend. This method should perform any necessary setup for the storage backend, such as establishing database connections or ensuring the existence of required files or schemas.

§Returns
  • Ok(()) on success.
  • Err(StoreError) if initialisation fails.
Source

fn get( &self, key: &str, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StoreError>> + Send + '_>>

Retrieves a value associated with a given key from the store.

§Arguments
  • key: A string slice that holds the key for the value to be retrieved.
§Returns
  • Ok(Some(Value)) if the key exists and the value is successfully retrieved.
  • Ok(None) if the key does not exist.
  • Err(StoreError) if there is an error retrieving the value.
Source

fn list( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<StoreModel>, StoreError>> + Send + '_>>

Lists all key-value pairs stored in the store.

§Returns
  • Ok(Vec<StoreModel>) containing all the key-value pairs in the store.
  • Err(StoreError) if there is an error listing the key-value pairs.
Source

fn set( &self, key: &str, value: Value, ttl: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<Option<StoreModel>, StoreError>> + Send + '_>>

Sets a value for a given key in the store, with an optional time-to-live (TTL).

§Arguments
  • key: The key under which the value is stored.
  • value: The value to set, represented as a serde_json::Value.
  • ttl: An optional u64 representing the time-to-live in seconds.
§Returns
  • Ok(()) if the value is successfully set.
  • Err(StoreError) if there is an error setting the value.
Source

fn remove( &self, key: &str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>

Removes a value associated with a given key from the store.

§Arguments
  • key: A string slice that holds the key for the value to be removed.
§Returns
  • Ok(()) if the key exists and the value is successfully removed.
  • Err(StoreError) if there is an error removing the value.
Source

fn remove_many( &self, keys: &[&str], ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>

Removes multiple values associated with the given keys from the store.

§Arguments
  • keys: A slice of string slices representing the keys for the values to be removed.
§Returns
  • Ok(()) if the values are successfully removed.
  • Err(StoreError) if there is an error removing the values.
Source

fn clear( &self, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>

Clears all values from the store.

§Returns
  • Ok(()) if the store is successfully cleared.
  • Err(StoreError) if there is an error clearing the store.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§