1use std::cmp;
5
6use crate::{
7 common::CommitVersion,
8 encoded::{encoded::EncodedValues, key::EncodedKey},
9};
10
11#[derive(Debug, PartialEq, Eq)]
12pub enum Delta {
13 Set {
14 key: EncodedKey,
15 values: EncodedValues,
16 },
17 Unset {
20 key: EncodedKey,
21 values: EncodedValues,
22 },
23 Remove {
26 key: EncodedKey,
27 },
28 Drop {
33 key: EncodedKey,
34 up_to_version: Option<CommitVersion>,
37 keep_last_versions: Option<usize>,
42 },
43}
44
45impl PartialOrd for Delta {
46 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
47 Some(self.cmp(other))
48 }
49}
50
51impl Ord for Delta {
52 fn cmp(&self, other: &Self) -> cmp::Ordering {
53 self.key().cmp(other.key())
54 }
55}
56
57impl Delta {
58 pub fn key(&self) -> &EncodedKey {
60 match self {
61 Self::Set {
62 key,
63 ..
64 } => key,
65 Self::Unset {
66 key,
67 ..
68 } => key,
69 Self::Remove {
70 key,
71 } => key,
72 Self::Drop {
73 key,
74 ..
75 } => key,
76 }
77 }
78
79 pub fn values(&self) -> Option<&EncodedValues> {
81 match self {
82 Self::Set {
83 values,
84 ..
85 } => Some(values),
86 Self::Unset {
87 ..
88 } => None,
89 Self::Remove {
90 ..
91 } => None,
92 Self::Drop {
93 ..
94 } => None,
95 }
96 }
97}
98
99impl Clone for Delta {
100 fn clone(&self) -> Self {
101 match self {
102 Self::Set {
103 key,
104 values,
105 } => Self::Set {
106 key: key.clone(),
107 values: values.clone(),
108 },
109 Self::Unset {
110 key,
111 values,
112 } => Self::Unset {
113 key: key.clone(),
114 values: values.clone(),
115 },
116 Self::Remove {
117 key,
118 } => Self::Remove {
119 key: key.clone(),
120 },
121 Self::Drop {
122 key,
123 up_to_version,
124 keep_last_versions,
125 } => Self::Drop {
126 key: key.clone(),
127 up_to_version: *up_to_version,
128 keep_last_versions: *keep_last_versions,
129 },
130 }
131 }
132}