Skip to main content

BlobBackend

Trait BlobBackend 

Source
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§

Source

fn backend(&self) -> &str

The backend’s name as it appears in matrix rows (memory, fs, s3).

Source

fn version(&self) -> &str

The backend’s version string as it appears in matrix rows.

Source

fn read( &self, key: &str, ) -> impl Future<Output = Result<Option<Vec<u8>>, BlobError>> + Send

The value at key, or None if absent.

Source

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.

Source

fn delete( &self, key: &str, ) -> impl Future<Output = Result<(), BlobError>> + Send

Remove key. Removing an absent key is Ok.

Source

fn stat( &self, key: &str, ) -> impl Future<Output = Result<Option<Entry>, BlobError>> + Send

The entry at key without reading its value, or None if absent.

Source

fn list( &self, prefix: &str, after: Option<&str>, limit: usize, ) -> impl Future<Output = Result<Page, BlobError>> + Send

Up to limit entries whose key starts with the literal prefix, in ascending bytewise key order, strictly after after if given.

Provided Methods§

Source

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.

Source

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.

Source

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".

Implementors§