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
62
63
64
65
66
67
68
69
70
71
72
73
// 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)
/// Value type (regular value or tombstone)
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(test, derive(strum::EnumIter))]
pub enum ValueType {
/// Existing value
Value,
/// Deleted value
Tombstone,
/// "Weak" deletion (a.k.a. `SingleDelete` in `RocksDB`)
WeakTombstone,
/// Merge operand
///
/// Stores a partial update that will be combined with other operands
/// and/or a base value via a user-provided [`crate::MergeOperator`].
MergeOperand = 3,
/// Value pointer
///
/// Points to a blob in a blob file.
Indirection = 4,
}
impl ValueType {
/// Returns `true` if the type is a tombstone marker (either normal or weak).
#[must_use]
pub fn is_tombstone(self) -> bool {
self == Self::Tombstone || self == Self::WeakTombstone
}
pub(crate) fn is_indirection(self) -> bool {
self == Self::Indirection
}
/// Returns `true` if the type is a merge operand.
#[must_use]
pub fn is_merge_operand(self) -> bool {
self == Self::MergeOperand
}
}
impl TryFrom<u8> for ValueType {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(Self::Value),
1 => Ok(Self::Tombstone),
2 => Ok(Self::WeakTombstone),
3 => Ok(Self::MergeOperand),
4 => Ok(Self::Indirection),
_ => Err(()),
}
}
}
impl From<ValueType> for u8 {
fn from(value: ValueType) -> Self {
match value {
ValueType::Value => 0,
ValueType::Tombstone => 1,
ValueType::WeakTombstone => 2,
ValueType::MergeOperand => 3,
ValueType::Indirection => 4,
}
}
}