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 overRga<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).
- AWMap
Delta - Delta for
AWMap: new tags and tombstones since another state. - GCounter
- A grow-only counter (G-Counter).
- GCounter
Delta - Delta for
GCounter: only the entries whereselfis ahead ofother. - GSet
- A grow-only set (G-Set).
- GSet
Delta - Delta for
GSet: elements present in self but not in other. - LWWMap
- A last-writer-wins map (LWW-Map).
- LWWMap
Delta - Delta for
LWWMap: entries that are newer in the source. - LWWRegister
- A last-writer-wins register (LWW-Register).
- LWWRegister
Delta - Delta for
LWWRegister: the register state if newer, orNoneif the other replica is already up to date. - MVRegister
- A multi-value register (MV-Register).
- MVRegister
Delta - 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.
- ORSet
Delta - Delta for
ORSet: new element tags and new tombstones since another state. - PNCounter
- A positive-negative counter (PN-Counter).
- PNCounter
Delta - Delta for
PNCounter: deltas for both the increment and decrement counters. - Text
Crdt - A collaborative text CRDT based on RGA (Replicated Growable Array).
- TwoPSet
- A two-phase set (2P-Set).
- TwoP
SetDelta - Delta for
TwoPSet: new additions and new removals.
Enums§
- Text
Error - Error type for TextCrdt operations.
Traits§
Type Aliases§
- NodeId
- Compact node identifier for CRDT replicas.
- Text
Delta - Delta for
TextCrdt— delegates toRgaDelta<char>.