pub trait Store: Send + Sync {
// Required methods
fn get(&self, key: &str) -> Result<Option<Vec<u8>>>;
fn put(&self, key: &str, bytes: &[u8]) -> Result<()>;
fn exists(&self, key: &str) -> Result<bool>;
fn delete(&self, key: &str) -> Result<()>;
fn list(&self, prefix: &str) -> Result<Vec<String>>;
fn health(&self) -> Result<()>;
// Provided methods
fn put_if_absent(&self, key: &str, bytes: &[u8]) -> Result<bool> { ... }
fn list_paginated(
&self,
prefix: &str,
after: Option<&str>,
limit: usize,
) -> Result<(Vec<String>, Option<String>)> { ... }
fn reader(&self, key: &str) -> Result<Box<dyn Read + '_>> { ... }
fn writer(&self, key: &str) -> Result<Box<dyn Write + '_>> { ... }
}Expand description
A location-agnostic byte store keyed by /-delimited UTF-8 paths.
Semantics every backend must honour (enforced by the shared contract
suite in [contract]):
putoverwrites an existing key.geton a missing key returnsOk(None);readerreturnsStoreError::NotFound.deleteof a missing key is idempotent (Ok).list(prefix)returns every key for whichkey.starts_with(prefix).
Required Methods§
Sourcefn put(&self, key: &str, bytes: &[u8]) -> Result<()>
fn put(&self, key: &str, bytes: &[u8]) -> Result<()>
Store bytes at key, overwriting any existing object.
Sourcefn delete(&self, key: &str) -> Result<()>
fn delete(&self, key: &str) -> Result<()>
Remove key. Removing a missing key succeeds (idempotent).
Provided Methods§
Sourcefn put_if_absent(&self, key: &str, bytes: &[u8]) -> Result<bool>
fn put_if_absent(&self, key: &str, bytes: &[u8]) -> Result<bool>
Atomically write bytes at key only if no object exists there.
Returns true if it was written, false if the key already existed.
The default is a non-atomic exists-then-put, safe only without
concurrent writers. Networked backends override it with a genuinely
atomic operation (S3 If-None-Match, Redis SET NX, Postgres
ON CONFLICT DO NOTHING).
Sourcefn list_paginated(
&self,
prefix: &str,
after: Option<&str>,
limit: usize,
) -> Result<(Vec<String>, Option<String>)>
fn list_paginated( &self, prefix: &str, after: Option<&str>, limit: usize, ) -> Result<(Vec<String>, Option<String>)>
A keyset page of keys under prefix, sorted ascending, starting strictly
after after (exclusive), at most limit keys. Returns the page plus a
cursor to pass as the next after when more keys may remain (None once
exhausted). limit == 0 yields an empty page.
The default lists everything and slices in memory; S3 and Postgres
override it with native keyset pagination (start-after / key > $after).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".