crdt_kit/lib.rs
1//! # crdt-kit
2//!
3//! CRDTs optimized for edge computing and local-first applications.
4//!
5//! A CRDT (Conflict-free Replicated Data Type) is a data structure that can be
6//! replicated across multiple devices and updated independently. When replicas
7//! are merged, they are guaranteed to converge to the same state without
8//! requiring coordination or consensus.
9//!
10//! ## Quick Start
11//!
12//! ```
13//! use crdt_kit::prelude::*;
14//!
15//! // Grow-only counter
16//! let mut c1 = GCounter::new("device-1");
17//! c1.increment();
18//!
19//! let mut c2 = GCounter::new("device-2");
20//! c2.increment();
21//!
22//! c1.merge(&c2);
23//! assert_eq!(c1.value(), 2);
24//! ```
25//!
26//! ## Available CRDTs
27//!
28//! ### Counters
29//! - [`GCounter`] - Grow-only counter (increment only)
30//! - [`PNCounter`] - Positive-negative counter (increment and decrement)
31//!
32//! ### Registers
33//! - [`LWWRegister`] - Last-writer-wins register (timestamp-based resolution)
34//! - [`MVRegister`] - Multi-value register (preserves concurrent writes)
35//!
36//! ### Sets
37//! - [`GSet`] - Grow-only set (add only)
38//! - [`TwoPSet`] - Two-phase set (add and remove, remove is permanent)
39//! - [`ORSet`] - Observed-remove set (add and remove freely)
40//!
41//! ## The `Crdt` Trait
42//!
43//! All types implement the [`Crdt`] trait, which provides the [`Crdt::merge`]
44//! method. Merge is guaranteed to be commutative, associative, and idempotent.
45
46mod crdt;
47mod gcounter;
48mod gset;
49mod lww_register;
50mod mv_register;
51mod or_set;
52mod pncounter;
53mod twop_set;
54
55pub mod prelude;
56
57pub use crdt::Crdt;
58pub use gcounter::GCounter;
59pub use gset::GSet;
60pub use lww_register::LWWRegister;
61pub use mv_register::MVRegister;
62pub use or_set::ORSet;
63pub use pncounter::PNCounter;
64pub use twop_set::TwoPSet;