aboutsummaryrefslogtreecommitdiff
path: root/src/util/crdt/crdt.rs
diff options
context:
space:
mode:
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.