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
type ColumnFamilyIdentifier: ColumnFamilies
The column family identifier type used by this storage.
type Error
type Error
The error type returned by storage operations.
Required Methods§
fn get_bytes(
&self,
key: &[u8],
column_family: &str,
) -> Result<Option<Self::ByteSlice<'_>>, Self::Error>
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>
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>
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>
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>
fn batch_write<'a>( &self, commands: impl IntoIterator<Item = BatchCommand<'a, &'a str>>, ) -> Result<(), Self::Error>
Perform a batch write operation on 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.