1use std::ops::Bound;
2
3#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
5pub struct Sequence(u64);
6
7impl Sequence {
8 pub const ZERO: Self = Self(0);
10
11 #[must_use]
13 pub const fn new(value: u64) -> Self {
14 Self(value)
15 }
16
17 #[must_use]
19 pub const fn get(self) -> u64 {
20 self.0
21 }
22
23 #[must_use]
25 pub const fn next(self) -> Option<Self> {
26 match self.0.checked_add(1) {
27 Some(value) => Some(Self(value)),
28 None => None,
29 }
30 }
31}
32
33pub type Value = Vec<u8>;
35
36#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct KeyValue {
39 pub key: Vec<u8>,
41 pub value: Value,
43}
44
45impl KeyValue {
46 #[must_use]
48 pub fn new(key: impl Into<Vec<u8>>, value: impl Into<Value>) -> Self {
49 Self {
50 key: key.into(),
51 value: value.into(),
52 }
53 }
54}
55
56#[derive(Debug, Clone, PartialEq, Eq)]
58pub struct KeyRange {
59 pub start: Bound<Vec<u8>>,
61 pub end: Bound<Vec<u8>>,
63}
64
65impl KeyRange {
66 #[must_use]
68 pub const fn all() -> Self {
69 Self {
70 start: Bound::Unbounded,
71 end: Bound::Unbounded,
72 }
73 }
74
75 #[must_use]
77 pub fn half_open(start: impl Into<Vec<u8>>, end: impl Into<Vec<u8>>) -> Self {
78 Self {
79 start: Bound::Included(start.into()),
80 end: Bound::Excluded(end.into()),
81 }
82 }
83}
84
85impl Default for KeyRange {
86 fn default() -> Self {
87 Self::all()
88 }
89}
90
91#[derive(Debug, Clone, Copy, PartialEq, Eq)]
93pub struct CommitInfo {
94 sequence: Sequence,
95}
96
97impl CommitInfo {
98 #[must_use]
100 pub const fn new(sequence: Sequence) -> Self {
101 Self { sequence }
102 }
103
104 #[must_use]
106 pub const fn sequence(self) -> Sequence {
107 self.sequence
108 }
109}