armdb 0.12.0

sharded bitcask key-value storage optimized for NVMe
Documentation
use std::hash::Hash;

use crate::const_map::ConstMapShard;
use crate::const_tree::ConstShard;
use crate::durability::Durability;
use crate::error::DbResult;
use crate::held_ops::HeldOps;
use crate::hook::WriteHook;
use crate::key::Key;

impl<K: Key, const V: usize, H: WriteHook<K>, D: Durability> HeldOps
    for ConstShard<'_, K, V, H, D>
{
    type Key = K;
    type Val = [u8; V];

    fn try_contains(&mut self, key: &K) -> DbResult<bool> {
        ConstShard::try_contains(self, key)
    }

    fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&[u8; V]) -> R) -> DbResult<Option<R>> {
        Ok(ConstShard::try_get(self, key)?.map(|value| f(&value)))
    }

    fn put(&mut self, key: &K, value: [u8; V]) -> DbResult<()> {
        ConstShard::put(self, key, &value).map(drop)
    }

    fn delete(&mut self, key: &K) -> DbResult<()> {
        ConstShard::delete(self, key).map(drop)
    }
}

impl<K: Key + Send + Sync + Hash + Eq, const V: usize, H: WriteHook<K>, D: Durability> HeldOps
    for ConstMapShard<'_, K, V, H, D>
{
    type Key = K;
    type Val = [u8; V];

    fn try_contains(&mut self, key: &K) -> DbResult<bool> {
        ConstMapShard::try_contains(self, key)
    }

    fn with_value<R>(&mut self, key: &K, f: impl FnOnce(&[u8; V]) -> R) -> DbResult<Option<R>> {
        Ok(ConstMapShard::try_get(self, key)?.map(|value| f(&value)))
    }

    fn put(&mut self, key: &K, value: [u8; V]) -> DbResult<()> {
        ConstMapShard::put(self, key, &value).map(drop)
    }

    fn delete(&mut self, key: &K) -> DbResult<()> {
        ConstMapShard::delete(self, key).map(drop)
    }
}