logicaffeine_data/crdt/delta.rs
1//! Delta CRDT trait and types.
2//!
3//! Trait for CRDTs that support delta-state synchronization.
4
5use super::causal::VClock;
6use super::Merge;
7use serde::{de::DeserializeOwned, Serialize};
8
9/// A CRDT that supports delta-state synchronization.
10///
11/// Delta-state CRDTs can extract small deltas representing recent changes,
12/// rather than broadcasting the entire state. This is more efficient for
13/// large data structures.
14pub trait DeltaCrdt: Merge + Sized {
15 /// The type of delta this CRDT produces.
16 type Delta: Serialize + DeserializeOwned + Clone + Send + 'static;
17
18 /// Extract a delta containing changes since the given version.
19 ///
20 /// Returns `None` if the delta history doesn't go back far enough.
21 fn delta_since(&self, version: &VClock) -> Option<Self::Delta>;
22
23 /// Apply an incoming delta to this CRDT.
24 fn apply_delta(&mut self, delta: &Self::Delta);
25
26 /// Get the current version (vector clock) of this CRDT.
27 fn version(&self) -> VClock;
28}