use std::hash::Hash;
use crate::durability::Durability;
use crate::error::DbResult;
use crate::held_ops::HeldOps;
use crate::hook::WriteHook;
use crate::key::Key;
use crate::zero_map::ZeroMapShard;
use crate::zero_tree::ZeroShard;
impl<K, const V: usize, T, D, WH> HeldOps for ZeroShard<'_, K, V, T, D, WH>
where
K: Key,
T: Copy + zerocopy::IntoBytes + zerocopy::FromBytes + zerocopy::Immutable,
D: Durability,
WH: WriteHook<K>,
{
type Key = K;
type Val = T;
fn try_contains(&mut self, key: &K) -> DbResult<bool> {
ZeroShard::try_contains(self, key)
}
fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&T) -> R) -> DbResult<Option<R>> {
Ok(ZeroShard::try_get(self, key)?.map(|value| f(&value)))
}
fn put(&mut self, key: &K, value: T) -> DbResult<()> {
ZeroShard::put(self, key, &value).map(drop)
}
fn delete(&mut self, key: &K) -> DbResult<()> {
ZeroShard::delete(self, key).map(drop)
}
}
impl<K, const V: usize, T, D, WH> HeldOps for ZeroMapShard<'_, K, V, T, D, WH>
where
K: Key + Send + Sync + Hash + Eq,
T: Copy + zerocopy::IntoBytes + zerocopy::FromBytes + zerocopy::Immutable,
D: Durability,
WH: WriteHook<K>,
{
type Key = K;
type Val = T;
fn try_contains(&mut self, key: &K) -> DbResult<bool> {
ZeroMapShard::try_contains(self, key)
}
fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&T) -> R) -> DbResult<Option<R>> {
Ok(ZeroMapShard::try_get(self, key)?.map(|value| f(&value)))
}
fn put(&mut self, key: &K, value: T) -> DbResult<()> {
ZeroMapShard::put(self, key, &value).map(drop)
}
fn delete(&mut self, key: &K) -> DbResult<()> {
ZeroMapShard::delete(self, key).map(drop)
}
}