Storage

Trait Storage 

Source
pub trait Storage:
    Clone
    + Send
    + Sync
    + 'static {
    type Blob: Blob;

    // Required methods
    fn open_versioned(
        &self,
        partition: &str,
        name: &[u8],
        versions: RangeInclusive<u16>,
    ) -> impl Future<Output = Result<(Self::Blob, u64, u16), Error>> + Send;
    fn remove(
        &self,
        partition: &str,
        name: Option<&[u8]>,
    ) -> impl Future<Output = Result<(), Error>> + Send;
    fn scan(
        &self,
        partition: &str,
    ) -> impl Future<Output = Result<Vec<Vec<u8>>, Error>> + Send;

    // Provided method
    fn open(
        &self,
        partition: &str,
        name: &[u8],
    ) -> impl Future<Output = Result<(Self::Blob, u64), Error>> + Send { ... }
}
Expand description

Interface to interact with storage.

To support storage implementations that enable concurrent reads and writes, blobs are responsible for maintaining synchronization.

Storage can be backed by a local filesystem, cloud storage, etc.

§Partition Names

Partition names must be non-empty and contain only ASCII alphanumeric characters, dashes (-), or underscores (_). Names containing other characters (e.g., /, ., spaces) will return an error.

Required Associated Types§

Source

type Blob: Blob

The readable/writeable storage buffer that can be opened by this Storage.

Required Methods§

Source

fn open_versioned( &self, partition: &str, name: &[u8], versions: RangeInclusive<u16>, ) -> impl Future<Output = Result<(Self::Blob, u64, u16), Error>> + Send

Open an existing blob in a given partition or create a new one, returning the blob and its length.

Multiple instances of the same blob can be opened concurrently, however, writing to the same blob concurrently may lead to undefined behavior.

An Ok result indicates the blob is durably created (or already exists).

§Versions

Blobs are versioned. If the blob’s version is not in versions, returns Error::BlobVersionMismatch.

§Returns

A tuple of (blob, logical_size, blob_version).

Source

fn remove( &self, partition: &str, name: Option<&[u8]>, ) -> impl Future<Output = Result<(), Error>> + Send

Remove a blob from a given partition.

If no name is provided, the entire partition is removed.

An Ok result indicates the blob is durably removed.

Source

fn scan( &self, partition: &str, ) -> impl Future<Output = Result<Vec<Vec<u8>>, Error>> + Send

Return all blobs in a given partition.

Provided Methods§

Source

fn open( &self, partition: &str, name: &[u8], ) -> impl Future<Output = Result<(Self::Blob, u64), Error>> + Send

Storage::open_versioned with DEFAULT_BLOB_VERSION as the only value in the versions range. The blob version is omitted from the return value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Storage for commonware_runtime::deterministic::Context

Source§

type Blob = <Storage<Storage<Storage>> as Storage>::Blob

Source§

impl Storage for commonware_runtime::tokio::Context

Source§

type Blob = <Storage<Storage> as Storage>::Blob

Source§

impl<C> Storage for Cell<C>
where C: Storage,

Source§

type Blob = <C as Storage>::Blob