use core::future::Future;
use core::ops::Bound;
use crate::maybe_send::{MaybeSend, MaybeSync};
use crate::stream::KvPair;
pub trait RawKv {
type Error;
fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, Self::Error>;
fn scan(
&self,
start: Bound<&[u8]>,
end: Bound<&[u8]>,
forward: bool,
) -> Result<Vec<KvPair>, Self::Error>;
fn insert(&mut self, key: &[u8], value: &[u8]) -> Result<(), Self::Error>;
fn delete(&mut self, key: &[u8]) -> Result<(), Self::Error>;
fn clear_range(&mut self, start: Bound<&[u8]>, end: Bound<&[u8]>) -> Result<(), Self::Error>;
}
pub trait AsyncRawKv: MaybeSend + MaybeSync {
type Error: MaybeSend + MaybeSync;
fn get(
&self,
key: &[u8],
) -> impl Future<Output = Result<Option<Vec<u8>>, Self::Error>> + MaybeSend;
fn exists(&self, key: &[u8]) -> impl Future<Output = Result<bool, Self::Error>> + MaybeSend {
async move { Ok(self.get(key).await?.is_some()) }
}
fn scan(
&self,
start: Bound<&[u8]>,
end: Bound<&[u8]>,
forward: bool,
limit: Option<usize>,
) -> impl Future<Output = Result<Vec<KvPair>, Self::Error>> + MaybeSend;
fn insert(
&mut self,
key: &[u8],
value: &[u8],
) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
fn delete(&mut self, key: &[u8]) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
fn clear_range(
&mut self,
start: Bound<&[u8]>,
end: Bound<&[u8]>,
) -> impl Future<Output = Result<(), Self::Error>> + MaybeSend;
}