Skip to main content

Storage

Trait Storage 

Source
pub trait Storage: Send + Sync {
    // Required methods
    fn get(&self, key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>;
    fn set(
        &self,
        key: &[u8],
        value: Vec<u8>,
    ) -> BoxFuture<'_, Result<(), Error>>;
    fn increment(
        &self,
        key: &[u8],
        delta: i64,
    ) -> BoxFuture<'_, Result<i64, Error>>;
    fn list(&self, prefix: &Prefix) -> BoxFuture<'_, Result<KvPairs, Error>>;
    fn delete(&self, key: &[u8]) -> BoxFuture<'_, Result<(), Error>>;
}
Expand description

Generic async key-value storage backend for extensions.

Keys are raw bytes. The first PREFIX_LEN bytes are a fixed-width namespace prefix. All methods take &self and are dyn-compatible via BoxFuture. Implementations must be Send + Sync.

Required Methods§

Source

fn get(&self, key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>

Get a value by key. Returns None if the key does not exist.

Source

fn set(&self, key: &[u8], value: Vec<u8>) -> BoxFuture<'_, Result<(), Error>>

Set a key to a value, overwriting any existing value.

Source

fn increment(&self, key: &[u8], delta: i64) -> BoxFuture<'_, Result<i64, Error>>

Atomically increment a counter by delta, returning the new value. If the key does not exist, it is created with an initial value of delta.

Source

fn list(&self, prefix: &Prefix) -> BoxFuture<'_, Result<KvPairs, Error>>

List all key-value pairs whose keys start with prefix. Returned in arbitrary order.

Source

fn delete(&self, key: &[u8]) -> BoxFuture<'_, Result<(), Error>>

Delete a key. No-op if the key does not exist.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Storage for ()

Empty storage backend. Every method returns an error. Use as the S parameter in AppState<S, P> when embedding the gateway with no extensions configured — anything that does call into storage is a misconfiguration that should fail loudly rather than silently drop data or report fake “not found” reads.

Source§

fn get(&self, _key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>

Source§

fn set(&self, _key: &[u8], _value: Vec<u8>) -> BoxFuture<'_, Result<(), Error>>

Source§

fn increment( &self, _key: &[u8], _delta: i64, ) -> BoxFuture<'_, Result<i64, Error>>

Source§

fn list(&self, _prefix: &Prefix) -> BoxFuture<'_, Result<KvPairs, Error>>

Source§

fn delete(&self, _key: &[u8]) -> BoxFuture<'_, Result<(), Error>>

Implementors§