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