aboutsummaryrefslogtreecommitdiff
path: root/src/util/crdt/crdt.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-12-16 11:47:58 +0100
committerAlex Auvolat <alex@adnab.me>2022-01-04 12:45:52 +0100
commit0bbb6673e7ce703e470a3c2aad620ee5f009bc84 (patch)
tree844e95b50e2bc129403b679a6c5d63ff82940ad6 /src/util/crdt/crdt.rs
parent53f71b3a57b3c1828292e26b7865d31e9bec44d6 (diff)
downloadgarage-0bbb6673e7ce703e470a3c2aad620ee5f009bc84.tar.gz
garage-0bbb6673e7ce703e470a3c2aad620ee5f009bc84.zip
Model changes
Diffstat (limited to 'src/util/crdt/crdt.rs')
-rw-r--r--src/util/crdt/crdt.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/util/crdt/crdt.rs b/src/util/crdt/crdt.rs
index 9b5f230d..2508d03b 100644
--- a/src/util/crdt/crdt.rs
+++ b/src/util/crdt/crdt.rs
@@ -28,6 +28,17 @@ pub trait Crdt {
fn merge(&mut self, other: &Self);
}
+impl<T> Crdt for Option<T>
+where
+ T: Eq,
+{
+ fn merge(&mut self, other: &Self) {
+ if self != other {
+ *self = None;
+ }
+ }
+}
+
/// All types that implement `Ord` (a total order) can also implement a trivial CRDT
/// defined by the merge rule: `a ⊔ b = max(a, b)`. Implement this trait for your type
/// to enable this behavior.