Archive

Trait Archive 

Source
pub trait Archive {
    type Key: Array;
    type Value: Codec;

    // Required methods
    fn put(
        &mut self,
        index: u64,
        key: Self::Key,
        value: Self::Value,
    ) -> impl Future<Output = Result<(), Error>>;
    fn get(
        &self,
        identifier: Identifier<'_, Self::Key>,
    ) -> impl Future<Output = Result<Option<Self::Value>, Error>>;
    fn has(
        &self,
        identifier: Identifier<'_, Self::Key>,
    ) -> impl Future<Output = Result<bool, Error>>;
    fn next_gap(&self, index: u64) -> (Option<u64>, Option<u64>);
    fn sync(&mut self) -> impl Future<Output = Result<(), Error>>;
    fn close(self) -> impl Future<Output = Result<(), Error>>;
    fn destroy(self) -> impl Future<Output = Result<(), Error>>;

    // Provided method
    fn put_sync(
        &mut self,
        index: u64,
        key: Self::Key,
        value: Self::Value,
    ) -> impl Future<Output = Result<(), Error>> { ... }
}
Expand description

A write-once key-value store where each key is associated with a unique index.

Required Associated Types§

Source

type Key: Array

The type of the key.

Source

type Value: Codec

The type of the value.

Required Methods§

Source

fn put( &mut self, index: u64, key: Self::Key, value: Self::Value, ) -> impl Future<Output = Result<(), Error>>

Store an item in Archive. Both indices and keys are assumed to both be globally unique.

If the index already exists, put does nothing and returns. If the same key is stored multiple times at different indices (not recommended), any value associated with the key may be returned.

Source

fn get( &self, identifier: Identifier<'_, Self::Key>, ) -> impl Future<Output = Result<Option<Self::Value>, Error>>

Retrieve an item from Archive.

Source

fn has( &self, identifier: Identifier<'_, Self::Key>, ) -> impl Future<Output = Result<bool, Error>>

Check if an item exists in Archive.

Source

fn next_gap(&self, index: u64) -> (Option<u64>, Option<u64>)

Retrieve the end of the current range including index (inclusive) and the start of the next range after index (if it exists).

This is useful for driving backfill operations over the archive.

Source

fn sync(&mut self) -> impl Future<Output = Result<(), Error>>

Sync all pending writes.

Source

fn close(self) -> impl Future<Output = Result<(), Error>>

Close Archive (and underlying storage).

Any pending writes are synced prior to closing.

Source

fn destroy(self) -> impl Future<Output = Result<(), Error>>

Remove all persistent data created by this Archive.

Provided Methods§

Source

fn put_sync( &mut self, index: u64, key: Self::Key, value: Self::Value, ) -> impl Future<Output = Result<(), Error>>

Perform a Archive::put and Archive::sync in a single operation.

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<E: Storage + Metrics + Clock, K: Array, V: Codec> Archive for commonware_storage::archive::immutable::Archive<E, K, V>

Source§

type Key = K

Source§

type Value = V

Source§

impl<T: Translator, E: Storage + Metrics, K: Array, V: Codec> Archive for commonware_storage::archive::prunable::Archive<T, E, K, V>

Source§

type Key = K

Source§

type Value = V