Skip to main content

KvBackend

Trait KvBackend 

Source
pub trait KvBackend:
    Send
    + Sync
    + Debug {
    // Required methods
    fn get<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn set<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn set_with_ttl<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        value: &'life2 [u8],
        ttl_ns: u64,
    ) -> Pin<Box<dyn Future<Output = Result<(), KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn exists<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list_keys<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn increment<'life0, 'life1, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        delta: i64,
    ) -> Pin<Box<dyn Future<Output = Result<i64, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn compare_and_swap<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        key: &'life1 str,
        expected: Option<&'life2 [u8]>,
        new: &'life3 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;
}
Expand description

A pluggable asynchronous backend for KvStore.

When a backend is installed via KvStore::with_backend, the store’s *_async methods delegate their data operations to the backend instead of the local in-memory map. This is how “cluster mode” works: a Raft-backed implementation can route reads and writes through consensus while the existing synchronous local path (used by the WASM host) stays untouched.

Implementors are responsible for their own key validation, quota enforcement, and TTL semantics — the local fallback continues to apply the store’s own rules, but a clustered backend defines its own.

Required Methods§

Source

fn get<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a value by key. Returns None if the key is missing or expired.

§Errors

Returns a KvError when the backend rejects the key or fails to read.

Source

fn set<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Set a value.

§Errors

Returns a KvError when the backend rejects the key/value or fails to write.

Source

fn set_with_ttl<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, key: &'life1 str, value: &'life2 [u8], ttl_ns: u64, ) -> Pin<Box<dyn Future<Output = Result<(), KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Set a value with a TTL in nanoseconds.

§Errors

Returns a KvError when the backend rejects the key/value or fails to write.

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Delete a key. Returns true if the key existed and was deleted.

§Errors

Returns a KvError when the backend rejects the key or fails to write.

Source

fn exists<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Check if a key exists (and has not expired).

§Errors

Returns a KvError when the backend rejects the key or fails to read.

Source

fn list_keys<'life0, 'life1, 'async_trait>( &'life0 self, prefix: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

List all non-expired keys with a given prefix.

§Errors

Returns a KvError when the backend fails to read.

Source

fn increment<'life0, 'life1, 'async_trait>( &'life0 self, key: &'life1 str, delta: i64, ) -> Pin<Box<dyn Future<Output = Result<i64, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Increment a numeric value atomically, returning the new value.

§Errors

Returns a KvError when the backend rejects the key, the existing value is not a valid integer, or the write fails.

Source

fn compare_and_swap<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, key: &'life1 str, expected: Option<&'life2 [u8]>, new: &'life3 [u8], ) -> Pin<Box<dyn Future<Output = Result<bool, KvError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Compare-and-swap: set new only if the current value equals expected. Returns true if the swap succeeded.

§Errors

Returns a KvError when the backend rejects the key/value or the write fails.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§