KeyValueStorage

Trait KeyValueStorage 

pub trait KeyValueStorage: Debug {
    type ColumnFamilyIdentifier: ColumnFamilies;
    type Error;
    type ByteSlice<'a>: AsRef<[u8]> + 'a
       where Self: 'a;

    // Required methods
    fn get_bytes(
        &self,
        key: &[u8],
        column_family: &str,
    ) -> Result<Option<Self::ByteSlice<'_>>, Self::Error>;
    fn put(
        &self,
        key: &[u8],
        column_family: &str,
        value: impl AsRef<[u8]>,
    ) -> Result<(), Self::Error>;
    fn delete(&self, key: &[u8], column_family: &str) -> Result<(), Self::Error>;
    fn clear(&self, column_family: &str) -> Result<(), Self::Error>;
    fn batch_write<'a>(
        &self,
        commands: impl IntoIterator<Item = BatchCommand<'a, &'a str>>,
    ) -> Result<(), Self::Error>;
    fn iter(
        &self,
        column_family: &str,
    ) -> DbIterator<'_, Result<(Box<[u8]>, Box<[u8]>), Self::Error>>;
    fn is_empty(&self) -> Result<bool, Self::Error>;
}
Expand description

Type-safe key-value storage trait that uses strongly-typed column family identifiers.

This is the foundational trait that storage implementations should implement.

Required Associated Types§

type ColumnFamilyIdentifier: ColumnFamilies

The column family identifier type used by this storage.

type Error

The error type returned by storage operations.

type ByteSlice<'a>: AsRef<[u8]> + 'a where Self: 'a

The type of byte slice used in the storage.

Required Methods§

fn get_bytes( &self, key: &[u8], column_family: &str, ) -> Result<Option<Self::ByteSlice<'_>>, Self::Error>

Get raw bytes of the value from the storage.

fn put( &self, key: &[u8], column_family: &str, value: impl AsRef<[u8]>, ) -> Result<(), Self::Error>

Put a value into storage.

fn delete(&self, key: &[u8], column_family: &str) -> Result<(), Self::Error>

Delete a value from storage.

fn clear(&self, column_family: &str) -> Result<(), Self::Error>

Clear all values from a column family.

fn batch_write<'a>( &self, commands: impl IntoIterator<Item = BatchCommand<'a, &'a str>>, ) -> Result<(), Self::Error>

Perform a batch write operation on the storage.

fn iter( &self, column_family: &str, ) -> DbIterator<'_, Result<(Box<[u8]>, Box<[u8]>), Self::Error>>

Iterate over a column family, returning key-value tuples.

The iteration order and the visibility of changes during the iterator’s lifetime are dependent on the underlying storage.

fn is_empty(&self) -> Result<bool, Self::Error>

Returns true if there is no a single key-value pair in the storage.

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.

Implementations on Foreign Types§

§

impl<Spec> KeyValueStorage for RocksDb<Spec>
where Spec: DbSpec + 'static,

§

type ColumnFamilyIdentifier = <Spec as DbSpec>::ColumnFamilyIdentifier

§

type ByteSlice<'a> = RocksdbByteSlice<'a>

§

type Error = StorageError

§

fn get_bytes( &self, key: &[u8], column_family: &str, ) -> Result<Option<<RocksDb<Spec> as KeyValueStorage>::ByteSlice<'_>>, <RocksDb<Spec> as KeyValueStorage>::Error>

§

fn put( &self, key: &[u8], column_family: &str, value: impl AsRef<[u8]>, ) -> Result<(), <RocksDb<Spec> as KeyValueStorage>::Error>

§

fn delete( &self, key: &[u8], column_family: &str, ) -> Result<(), <RocksDb<Spec> as KeyValueStorage>::Error>

§

fn clear( &self, column_family: &str, ) -> Result<(), <RocksDb<Spec> as KeyValueStorage>::Error>

§

fn batch_write<'a>( &self, commands: impl IntoIterator<Item = BatchCommand<'a, &'a str>>, ) -> Result<(), <RocksDb<Spec> as KeyValueStorage>::Error>

§

fn iter( &self, column_family: &str, ) -> DbIterator<'_, Result<(Box<[u8]>, Box<[u8]>), <RocksDb<Spec> as KeyValueStorage>::Error>>

§

fn is_empty(&self) -> Result<bool, <RocksDb<Spec> as KeyValueStorage>::Error>

Implementors§

§

impl<CF> KeyValueStorage for InMemoryStorage<CF>
where CF: ColumnFamilies,

§

type ColumnFamilyIdentifier = CF

§

type Error = StorageError

§

type ByteSlice<'a> = InMemorySlice where InMemoryStorage<CF>: 'a