1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2024-present, fjall-rs
// This source code is licensed under both the Apache 2.0 and MIT License
// (found in the LICENSE-* files in the repository)
use lsm_tree::{Guard as _Guard, UserKey, UserValue};
/// Guard to access key-value pairs
pub struct Guard(pub(crate) lsm_tree::IterGuardImpl);
impl Guard {
/// Accesses the key-value pair if the predicate returns `true`.
///
/// The predicate receives the key - if returning `false`, the value
/// may not be loaded if the tree is key-value separated.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn into_inner_if(
self,
pred: impl Fn(&crate::UserKey) -> bool,
) -> crate::Result<(UserKey, Option<UserValue>)> {
self.0.into_inner_if(pred).map_err(Into::into)
}
/// Returns the key-value tuple.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn into_inner(self) -> crate::Result<crate::KvPair> {
self.0.into_inner().map_err(Into::into)
}
/// Returns the key.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn key(self) -> crate::Result<crate::UserKey> {
self.0.key().map_err(Into::into)
}
/// Returns the value size.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn size(self) -> crate::Result<u32> {
self.0.size().map_err(Into::into)
}
/// Returns the value.
///
/// # Errors
///
/// Will return `Err` if an IO error occurs.
pub fn value(self) -> crate::Result<crate::UserValue> {
self.0.value().map_err(Into::into)
}
}