Expand description
§postbox — lattice basics + async join cells
Part of the postbox workspace
Core pieces:
lattice: traits and helpers for lattices (join, meet, and bounded variants)crdt: classic state-based CRDTs built on those lattices:crdt::GCounter: grow-only countercrdt::PNCounter: increment/decrement counter built from two GCounterscrdt::GSet: grow-only setcrdt::TwoPSet: two-phase set (add + remove, no re-add)crdt::ORSet: observed-remove set (supports re-add)crdt::LWW: last-writer-wins register (with replica ID tiebreaker)crdt::MVRegister: multi-value register (keeps all concurrent writes)
lvar(feature = “async”): an LVar-style cell whose state only grows by lattice joinpropagator(feature = “async”): propagator networks for accumulative computation with semigroup-valued cellsjoin_stream_ext(feature = “async”): stream adapters to foldStream<Item = L>by lattice joinmvar(feature = “async”): a classic MVar (single-slot put/take), separate from the monotone cell
§Concepts
A join-semilattice is a type L with an operation join: &L × &L → L that is associative, commutative, and idempotent. It
induces an order x ≤ y iff x.join(y) == y.
- Common joins:
max(on numbers),union(on sets),min(on the dual order). - If a bottom element ⊥ exists, implement
BoundedJoinSemilatticeso you can fold from empty.
A meet-semilattice has the dual meet operation (greatest
lower bound). A lattice has both join and meet. When both
bottom and top exist, it’s a bounded lattice.
§Features
This crate has several optional features (all enabled by default):
-
async(enabled by default): Enables async/await support, including:lvar::LVar: monotone lattice variables with async waitingmvar::MVar: classic single-slot async cellsjoin_stream_ext: stream folding with lattice join- Requires
tokioandfuturesdependencies
-
derive(enabled by default): Provides derive macros for automatic trait implementations:#[derive(JoinSemilattice)]: derive join from field-wise joins#[derive(BoundedJoinSemilattice)]: derive bottom from field-wise bottoms#[derive(MeetSemilattice)]: derive meet from field-wise meets#[derive(BoundedMeetSemilattice)]: derive top from field-wise tops
-
bitflags(enabled by default): Adds support for usingBitOrwith types from thebitflagscrate- Enables testing and documentation for bitflags integration
To use only the core lattice types without async or derives:
postbox = { version = "…", default-features = false }§Quick start
use std::collections::HashSet;
use postbox::lattice::BoundedJoinSemilattice;
use postbox::lattice::JoinSemilattice;
// Join = union on sets
let a: HashSet<_> = [1,2].into_iter().collect();
let b: HashSet<_> = [2,3].into_iter().collect();
let j = a.join(&b);
assert_eq!(j, HashSet::from([1,2,3]));
assert!(HashSet::<i32>::bottom().is_empty());§Async example
postbox = { version = "…", features = ["async"] }ⓘ
use std::collections::HashSet;
use postbox::LVar;
let cell = LVar::<HashSet<&'static str>>::new();
let target: HashSet<_> = ["a","b","c"].into_iter().collect();
let waiter = {
let cell = cell.clone();
tokio::spawn(async move { cell.await_at_least(&target).await })
};
cell.put_join(&HashSet::from(["a"]));
cell.put_join(&HashSet::from(["b","c"]));
let got = waiter.await.unwrap();
assert!(target.is_subset(&got));Modules§
- crdt
- CRDTs built on lattice combinators Basic state-based CRDTs built on lattice primitives.
- join_
stream_ ext - Stream extensions for folding by lattice joins (uses
futures::Stream). Stream extensions for join-semilattices (feature ="async"). - lattice
- Core algebra: lattice traits (join, meet, bounded variants) and standard helpers. Core lattice traits and building blocks.
- lvar
- Join-only, monotone cell (LVar): state increases via lattice
join. Async LVar-style monotone cell built on join-semilattices. - mvar
- A classic single-slot async MVar (blocking put/take). Not monotone. MVar-style for Rust (tokio)
- propagator
- Propagator networks for monotonic computation with lattice-valued cells. Propagator networks for accumulative computation with algebraic cells.
Traits§
- Bounded
Join Semilattice - A bounded join-semilattice: a join-semilattice with a bottom element.
- Bounded
Lattice - A bounded lattice: a lattice with both bottom and top elements.
- Bounded
Meet Semilattice - A bounded meet-semilattice: a meet-semilattice with a top element.
- Join
Semilattice - A join-semilattice: a type with an associative, commutative, idempotent binary operation.
- Lattice
- A lattice: a type with both join (least upper bound) and meet (greatest lower bound) operations.
- Meet
Semilattice - A meet-semilattice: a type with an associative, commutative, idempotent binary operation that computes greatest lower bounds.
Derive Macros§
- Bounded
Join Semilattice - Derive macro for
BoundedJoinSemilattice. - Bounded
Meet Semilattice - Derive macro for
BoundedMeetSemilattice. - Join
Semilattice - Derive macro for
JoinSemilattice. - Meet
Semilattice - Derive macro for
MeetSemilattice.