use core::ops::Range;
use core::{error::Error, fmt::Debug};
use crate::{BatchOp, BufferOverflowError, UnifierData};
pub trait Repository {
type K: UnifierData;
type V: UnifierData;
type Error: Debug + Error + From<BufferOverflowError>;
fn insert_entry(
&mut self,
key: <Self::K as UnifierData>::View<'_>,
value: <Self::V as UnifierData>::View<'_>,
) -> Result<(), Self::Error>;
fn get_entry(
&self,
key: <Self::K as UnifierData>::View<'_>,
) -> Result<Option<Self::V>, Self::Error>;
fn remove_entry(
&mut self,
key: <Self::K as UnifierData>::View<'_>,
) -> Result<Option<Self::V>, Self::Error>;
fn scan_range(
&self,
range: Range<Self::K>,
) -> Result<impl Iterator<Item = IterationItem<Self::K, Self::Error>>, Self::Error>;
fn apply<'a>(
&mut self,
operations: impl Iterator<Item = BatchOp<'a, Self::K, Self::V>>,
) -> Result<(), Self::Error> {
for op in operations {
match op {
BatchOp::Insert { key, value } => {
self.insert_entry(key, value)?;
}
BatchOp::Delete { key } => {
self.remove_entry(key)?;
}
}
}
Ok(())
}
}
type IterationItem<K, E> = Result<K, E>;