use std::hash::Hash;
use crate::byte_view::ByteView;
use crate::error::DbResult;
use crate::held_ops::HeldOps;
use crate::hook::WriteHook;
use crate::key::Key;
use crate::var_map::VarMapShard;
use crate::var_tree::VarShard;
impl<K: Key, H: WriteHook<K>> HeldOps for VarShard<'_, K, H> {
type Key = K;
type Val = ByteView;
fn try_contains(&mut self, key: &K) -> DbResult<bool> {
VarShard::try_contains(self, key)
}
fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&ByteView) -> R) -> DbResult<Option<R>> {
Ok(VarShard::try_get(self, key)?.map(|value| f(&value)))
}
fn put(&mut self, key: &K, value: ByteView) -> DbResult<()> {
VarShard::put(self, key, value.as_ref()).map(drop)
}
fn delete(&mut self, key: &K) -> DbResult<()> {
VarShard::delete(self, key).map(drop)
}
}
impl<K: Key + Send + Sync + Hash + Eq, H: WriteHook<K>> HeldOps for VarMapShard<'_, K, H> {
type Key = K;
type Val = ByteView;
fn try_contains(&mut self, key: &K) -> DbResult<bool> {
VarMapShard::try_contains(self, key)
}
fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&ByteView) -> R) -> DbResult<Option<R>> {
Ok(VarMapShard::try_get(self, key)?.map(|value| f(&value)))
}
fn put(&mut self, key: &K, value: ByteView) -> DbResult<()> {
VarMapShard::put(self, key, value.as_ref()).map(drop)
}
fn delete(&mut self, key: &K) -> DbResult<()> {
VarMapShard::delete(self, key).map(drop)
}
}