lsm_tree/
iter_guard.rs

1use crate::{
2    blob_tree::Guard as BlobGuard, tree::Guard as StandardGuard, KvPair, UserKey, UserValue,
3};
4use enum_dispatch::enum_dispatch;
5
6/// Guard to access key-value pairs
7#[enum_dispatch]
8pub trait IterGuard {
9    /// Accesses the key-value pair.
10    ///
11    /// # Errors
12    ///
13    /// Will return `Err` if an IO error occurs.
14    fn into_inner(self) -> crate::Result<KvPair>;
15
16    /// Accesses the key.
17    ///
18    /// # Errors
19    ///
20    /// Will return `Err` if an IO error occurs.
21    fn key(self) -> crate::Result<UserKey>;
22
23    /// Returns the value size.
24    ///
25    /// # Errors
26    ///
27    /// Will return `Err` if an IO error occurs.
28    fn size(self) -> crate::Result<u32>;
29
30    /// Accesses the value.
31    ///
32    /// # Errors
33    ///
34    /// Will return `Err` if an IO error occurs.
35    fn value(self) -> crate::Result<UserValue>
36    where
37        Self: Sized,
38    {
39        self.into_inner().map(|(_, v)| v)
40    }
41}
42
43#[enum_dispatch(IterGuard)]
44pub enum IterGuardImpl<'a> {
45    Standard(StandardGuard),
46    Blob(BlobGuard<'a>),
47}