use crate::storage::{
BeginScanOptions, CommitResult, GetManyRequest, GetManyResult, Key, KeyRange, PutBatch,
ReadOptions, ScanCursor, StorageError, StorageSpace, WriteOptions,
};
pub trait Storage: Send + Sync {
type Read<'a>: StorageRead + 'a
where
Self: 'a;
type Write<'a>: StorageWrite + 'a
where
Self: 'a;
fn begin_read(
&self,
opts: ReadOptions,
) -> impl Future<Output = Result<Self::Read<'_>, StorageError>> + Send;
fn begin_write(
&self,
opts: WriteOptions,
) -> impl Future<Output = Result<Self::Write<'_>, StorageError>> + Send;
}
pub trait StorageRead: Send + Sync {
fn snapshot_cache_key(&self) -> Option<u128> {
None
}
fn get_many(
&self,
requests: &[GetManyRequest<'_>],
) -> impl Future<Output = Result<GetManyResult, StorageError>> + Send;
fn begin_scan(
&self,
space: StorageSpace,
range: KeyRange,
opts: BeginScanOptions,
) -> impl Future<Output = Result<ScanCursor<'_>, StorageError>> + Send;
}
pub trait StorageWrite: Send {
fn put_many(
&mut self,
space: StorageSpace,
entries: PutBatch,
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn delete_many(
&mut self,
space: StorageSpace,
keys: &[Key],
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn delete_range(
&mut self,
space: StorageSpace,
range: KeyRange,
) -> impl Future<Output = Result<(), StorageError>> + Send;
fn commit(self) -> impl Future<Output = Result<CommitResult, StorageError>> + Send;
fn rollback(self) -> impl Future<Output = Result<(), StorageError>> + Send;
}