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§
Sourcefn get(&self, key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>
fn get(&self, key: &[u8]) -> BoxFuture<'_, Result<Option<Vec<u8>>, Error>>
Get a value by key. Returns None if the key does not exist.
Sourcefn set(&self, key: &[u8], value: Vec<u8>) -> BoxFuture<'_, Result<(), Error>>
fn set(&self, key: &[u8], value: Vec<u8>) -> BoxFuture<'_, Result<(), Error>>
Set a key to a value, overwriting any existing value.
Sourcefn increment(&self, key: &[u8], delta: i64) -> BoxFuture<'_, Result<i64, Error>>
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.
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.
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.