Skip to main content

DeltaCrdt

Trait DeltaCrdt 

Source
pub trait DeltaCrdt: Crdt {
    type Delta;

    // Required methods
    fn delta(&self, other: &Self) -> Self::Delta;
    fn apply_delta(&mut self, delta: &Self::Delta);
}
Expand description

Extension trait for delta-state CRDTs.

Delta-state CRDTs can produce compact deltas representing only the changes between two states. This enables efficient synchronization: instead of transferring the full state, replicas exchange small deltas.

§Example

use crdt_kit::prelude::*;

let mut c1 = GCounter::new("a");
c1.increment();
c1.increment();

let mut c2 = GCounter::new("b");
c2.increment();

// Generate a delta from c1 that c2 doesn't have
let delta = c1.delta(&c2);

// Apply just the delta instead of full state merge
c2.apply_delta(&delta);
assert_eq!(c2.value(), 3); // both counts included

Required Associated Types§

Source

type Delta

The type of delta produced by this CRDT.

Required Methods§

Source

fn delta(&self, other: &Self) -> Self::Delta

Generate a delta containing changes in self that other does not have.

The returned delta is the minimal set of information needed to bring a replica at state other up to date with self.

Source

fn apply_delta(&mut self, delta: &Self::Delta)

Apply a delta to this replica’s state.

This is equivalent to merging the state that produced the delta, but typically much more efficient in terms of data transferred.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§