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.5.0", default-features = false }

§Quick Start

use crdt_kit::prelude::*;

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

let mut c2 = GCounter::new(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 (HLC-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)

§Maps

  • LWWMap - Last-writer-wins map (per-key HLC timestamp resolution)
  • AWMap - Add-wins map (OR-Set semantics for keys, concurrent add beats remove)

§Sequences

  • Rga - Replicated Growable Array (ordered sequence)
  • TextCrdt - Collaborative text (thin wrapper over Rga<char>)

§The Crdt Trait

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

Re-exports§

pub use rga::Rga;
pub use rga::RgaDelta;
pub use rga::RgaError;
pub use rga::RgaNode;
pub use version::CrdtType;
pub use version::EnvelopeError;
pub use version::VersionError;
pub use version::Versioned;
pub use version::VersionedEnvelope;
pub use version::ENVELOPE_HEADER_SIZE;
pub use version::MAGIC_BYTE;

Modules§

clock
Hybrid Logical Clock (HLC) for causal ordering.
prelude
Convenient re-exports for common usage.
rga
Replicated Growable Array (RGA) — ordered sequence CRDT.
version
Versioned serialization and envelope format. Versioned serialization for CRDTs.

Structs§

AWMap
An add-wins map (AW-Map).
AWMapDelta
Delta for AWMap: new tags and tombstones since another state.
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).
GSetDelta
Delta for GSet: elements present in self but not in other.
LWWMap
A last-writer-wins map (LWW-Map).
LWWMapDelta
Delta for LWWMap: entries that are newer in the source.
LWWRegister
A last-writer-wins register (LWW-Register).
LWWRegisterDelta
Delta for LWWRegister: the register state if newer, or None if the other replica is already up to date.
MVRegister
A multi-value register (MV-Register).
MVRegisterDelta
Delta for MVRegister: the full state needed to bring a peer up to date.
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.
TextCrdt
A collaborative text CRDT based on RGA (Replicated Growable Array).
TwoPSet
A two-phase set (2P-Set).
TwoPSetDelta
Delta for TwoPSet: new additions and new removals.

Enums§

TextError
Error type for TextCrdt operations.

Traits§

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

Type Aliases§

NodeId
Compact node identifier for CRDT replicas.
TextDelta
Delta for TextCrdt — delegates to RgaDelta<char>.