Skip to main content

lww_register/
lib.rs

1// Copyright 2023 Developers of the reconcile project.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9//! A small state-based last-write-wins register and Hybrid Logical Clock domain.
10//!
11//! [`Entry<T, V>`] is the generic register state. [`LwwRegister<V>`] is the recommended alias
12//! using this crate's [`Timestamp`] ordering. The crate intentionally contains no networking,
13//! membership, persistence, async runtime, storage codec, or wall-clock implementation.
14//!
15//! # Convergence contract
16//!
17//! Distinct conflicting writes must receive distinct stamps from one total order. With
18//! [`Timestamp`], give every independently writing replica a distinct [`NodeId`] and use a
19//! [`Clock`] implementation that satisfies [`assert_conformance`].
20#![forbid(unsafe_code)]
21#![deny(missing_docs)]
22
23pub mod clock;
24pub mod entry;
25
26pub use clock::{
27    assert_conformance, AdmittedTime, Clock, ClockDrift, Hlc, LogicalCounter, NodeId, PhysicalTime,
28    Timestamp, MAX_CLOCK_DRIFT,
29};
30pub use entry::{Entry, State};
31
32/// An LWW register using this crate's Hybrid Logical Clock [`Timestamp`] as its stamp.
33pub type LwwRegister<V> = Entry<Timestamp, V>;