pub trait BlobBackend: Send + Sync {
// Required methods
fn backend(&self) -> &str;
fn version(&self) -> &str;
fn read(
&self,
key: &str,
) -> impl Future<Output = Result<Option<Vec<u8>>, BlobError>> + Send;
fn write(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send;
fn delete(
&self,
key: &str,
) -> impl Future<Output = Result<(), BlobError>> + Send;
fn stat(
&self,
key: &str,
) -> impl Future<Output = Result<Option<Entry>, BlobError>> + Send;
fn list(
&self,
prefix: &str,
after: Option<&str>,
limit: usize,
) -> impl Future<Output = Result<Page, BlobError>> + Send;
// Provided methods
fn create_exclusive(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<bool, BlobError>> + Send { ... }
fn replace_atomic(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send { ... }
fn append(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send { ... }
}Expand description
A blob store: bytes by key.
Small on purpose. Every method is a primitive a capability’s contract is written against; a
method a backend cannot honour must fail with BlobError rather than approximate, and the
capability stays off because its test did not pass. Missing keys are Ok(None), not errors.
Required Methods§
Sourcefn read(
&self,
key: &str,
) -> impl Future<Output = Result<Option<Vec<u8>>, BlobError>> + Send
fn read( &self, key: &str, ) -> impl Future<Output = Result<Option<Vec<u8>>, BlobError>> + Send
The value at key, or None if absent.
Sourcefn write(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send
fn write( &self, key: &str, bytes: Vec<u8>, ) -> impl Future<Output = Result<(), BlobError>> + Send
Store bytes at key, replacing any earlier value. Atomicity is not implied; that is
blob.replace_atomic.
Sourcefn delete(
&self,
key: &str,
) -> impl Future<Output = Result<(), BlobError>> + Send
fn delete( &self, key: &str, ) -> impl Future<Output = Result<(), BlobError>> + Send
Remove key. Removing an absent key is Ok.
Provided Methods§
Sourcefn create_exclusive(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<bool, BlobError>> + Send
fn create_exclusive( &self, key: &str, bytes: Vec<u8>, ) -> impl Future<Output = Result<bool, BlobError>> + Send
Write bytes at key only if nothing is there. Ok(true) created it, Ok(false) found
a value and changed nothing. Of any number of concurrent callers for one key, exactly one
gets Ok(true) (blob.create_exclusive). A backend that cannot promise that returns
BlobError::Unsupported; the default does.
Sourcefn replace_atomic(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send
fn replace_atomic( &self, key: &str, bytes: Vec<u8>, ) -> impl Future<Output = Result<(), BlobError>> + Send
Replace the value at key so that a concurrent reader sees the whole old value or the
whole new one, never a mix (blob.replace_atomic.concurrent_read). A backend that cannot
promise that returns BlobError::Unsupported; the default does.
Sourcefn append(
&self,
key: &str,
bytes: Vec<u8>,
) -> impl Future<Output = Result<(), BlobError>> + Send
fn append( &self, key: &str, bytes: Vec<u8>, ) -> impl Future<Output = Result<(), BlobError>> + Send
Add bytes after the existing bytes of key, in call order (blob.append). Of
concurrent calls, each call’s bytes arrive whole and exactly once
(blob.append.concurrent_whole). A backend that cannot promise that returns
BlobError::Unsupported; the default does.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".