1use std::cmp;
5
6use reifydb_codec::{encoded::row::EncodedRow, key::encoded::EncodedKey};
7use serde::{Deserialize, Serialize};
8
9#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
10pub enum Delta {
11 Set {
12 key: EncodedKey,
13 row: EncodedRow,
14 },
15
16 Unset {
17 key: EncodedKey,
18 row: EncodedRow,
19 },
20
21 Remove {
22 key: EncodedKey,
23 },
24
25 Drop {
26 key: EncodedKey,
27 },
28}
29
30impl PartialOrd for Delta {
31 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
32 Some(self.cmp(other))
33 }
34}
35
36impl Ord for Delta {
37 fn cmp(&self, other: &Self) -> cmp::Ordering {
38 self.key().cmp(other.key())
39 }
40}
41
42impl Delta {
43 pub fn key(&self) -> &EncodedKey {
44 match self {
45 Self::Set {
46 key,
47 ..
48 } => key,
49 Self::Unset {
50 key,
51 ..
52 } => key,
53 Self::Remove {
54 key,
55 } => key,
56 Self::Drop {
57 key,
58 ..
59 } => key,
60 }
61 }
62
63 pub fn row(&self) -> Option<&EncodedRow> {
64 match self {
65 Self::Set {
66 row,
67 ..
68 } => Some(row),
69 Self::Unset {
70 ..
71 } => None,
72 Self::Remove {
73 ..
74 } => None,
75 Self::Drop {
76 ..
77 } => None,
78 }
79 }
80}
81
82impl Clone for Delta {
83 fn clone(&self) -> Self {
84 match self {
85 Self::Set {
86 key,
87 row,
88 } => Self::Set {
89 key: key.clone(),
90 row: row.clone(),
91 },
92 Self::Unset {
93 key,
94 row,
95 } => Self::Unset {
96 key: key.clone(),
97 row: row.clone(),
98 },
99 Self::Remove {
100 key,
101 } => Self::Remove {
102 key: key.clone(),
103 },
104 Self::Drop {
105 key,
106 } => Self::Drop {
107 key: key.clone(),
108 },
109 }
110 }
111}