Skip to main content

Crate crdt_kit

Crate crdt_kit 

Source
Expand description

§crdt-kit

CRDTs optimized for edge computing and local-first applications.

A CRDT (Conflict-free Replicated Data Type) is a data structure that can be replicated across multiple devices and updated independently. When replicas are merged, they are guaranteed to converge to the same state without requiring coordination or consensus.

§no_std Support

This crate supports no_std environments with the alloc crate. Disable the default std feature in your Cargo.toml:

[dependencies]
crdt-kit = { version = "0.2", default-features = false }

Note: LWWRegister::new and LWWRegister::set require the std feature for automatic timestamps via SystemTime.

§Quick Start

use crdt_kit::prelude::*;

// Grow-only counter
let mut c1 = GCounter::new("device-1");
c1.increment();

let mut c2 = GCounter::new("device-2");
c2.increment();

c1.merge(&c2);
assert_eq!(c1.value(), 2);

§Available CRDTs

§Counters

  • GCounter - Grow-only counter (increment only)
  • PNCounter - Positive-negative counter (increment and decrement)

§Registers

  • LWWRegister - Last-writer-wins register (timestamp-based resolution)
  • MVRegister - Multi-value register (preserves concurrent writes)

§Sets

  • GSet - Grow-only set (add only)
  • TwoPSet - Two-phase set (add and remove, remove is permanent)
  • ORSet - Observed-remove set (add and remove freely)

§The Crdt Trait

All types implement the Crdt trait, which provides the Crdt::merge method. Merge is guaranteed to be commutative, associative, and idempotent.

Modules§

prelude
Convenient re-exports for common usage.

Structs§

GCounter
A grow-only counter (G-Counter).
GCounterDelta
Delta for GCounter: only the entries where self is ahead of other.
GSet
A grow-only set (G-Set).
LWWRegister
A last-writer-wins register (LWW-Register).
MVRegister
A multi-value register (MV-Register).
ORSet
An observed-remove set (OR-Set), also known as an add-wins set.
ORSetDelta
Delta for ORSet: new element tags and new tombstones since another state.
PNCounter
A positive-negative counter (PN-Counter).
PNCounterDelta
Delta for PNCounter: deltas for both the increment and decrement counters.
Rga
A Replicated Growable Array (RGA) — an ordered sequence CRDT.
TextCrdt
A collaborative text CRDT based on RGA (Replicated Growable Array) principles.
TwoPSet
A two-phase set (2P-Set).

Traits§

Crdt
Core trait that all CRDTs must implement.
DeltaCrdt
Extension trait for delta-state CRDTs.