pub enum CrdtValue {
Set(ORSet<CrdtScalar>),
SetRemoveWins(ORSet<CrdtScalar, RemoveWins>),
Seq(RGA<CrdtScalar>),
Register(MVRegister<CrdtScalar>),
Counter(GCounter),
PnCounter(PNCounter),
Map(ORMap<CrdtScalar, LatestWrite<CrdtScalar>>),
}Expand description
A live CRDT held by the interpreter. Wraps the actual logicaffeine_data type, so its
convergence behaviour is identical to the compiled tier’s by construction.
Variants§
Set(ORSet<CrdtScalar>)
SharedSet of T / SharedSet (AddWins) — observed-remove set, add-wins on a
concurrent add/remove of the same element.
SetRemoveWins(ORSet<CrdtScalar, RemoveWins>)
SharedSet (RemoveWins) — observed-remove set, remove-wins on a concurrent
add/remove (e.g. an access-revocation / block list).
Seq(RGA<CrdtScalar>)
SharedSequence of T — replicated growable array (RGA). Stable, convergent
insertion order.
Register(MVRegister<CrdtScalar>)
Divergent T — multi-value register (MVRegister). Keeps concurrent writes until
one is resolved.
Counter(GCounter)
ConvergentCount — grow-only counter (GCounter): each replica owns a slot, the value
is the sum, and merge is per-replica MAX. State-based ⇒ IDEMPOTENT: redelivering the same
remote state never double-counts (the very property a bare-Int op-based counter lacks).
PnCounter(PNCounter)
Tally — increment/decrement counter (PNCounter): two G-Counters (increments and
decrements), value = Σinc − Σdec, merge per-replica MAX on both. Idempotent like Counter.
Map(ORMap<CrdtScalar, LatestWrite<CrdtScalar>>)
SharedMap from K to V — observed-remove keys (add-wins), each value a Lamport-stamped
last-writer register (ORMap<K, LatestWrite<V>>), exactly the compiled tier’s map.
Implementations§
Source§impl CrdtValue
impl CrdtValue
pub fn new_set(replica: ReplicaId) -> CrdtValue
pub fn new_set_remove_wins(replica: ReplicaId) -> CrdtValue
pub fn new_seq(replica: ReplicaId) -> CrdtValue
pub fn new_register(replica: ReplicaId) -> CrdtValue
pub fn new_counter(replica: ReplicaId) -> CrdtValue
pub fn new_pn_counter(replica: ReplicaId) -> CrdtValue
pub fn new_map(replica: ReplicaId) -> CrdtValue
Sourcepub fn map_put(
&mut self,
key: &RuntimeValue,
value: &RuntimeValue,
) -> Result<(), String>
pub fn map_put( &mut self, key: &RuntimeValue, value: &RuntimeValue, ) -> Result<(), String>
Set <map>[key] to value.
Sourcepub fn map_get(&self, key: &RuntimeValue) -> Result<RuntimeValue, String>
pub fn map_get(&self, key: &RuntimeValue) -> Result<RuntimeValue, String>
<map>[key] — the value under a PRESENT key; a missing key traps exactly as a Map’s does.
Sourcepub fn bump(&mut self, amount: i64) -> Result<(), String>
pub fn bump(&mut self, amount: i64) -> Result<(), String>
Increase/Decrease <counter> by N — bump this replica’s own slot. A grow-only
ConvergentCount rejects a decrement (that is what a Tally is for); a Tally takes both.
The per-replica slot is what makes a later merge idempotent.
Sourcepub fn counter_value(&self) -> Option<i64>
pub fn counter_value(&self) -> Option<i64>
The integer value of a counter (GCounter sum, or PNCounter inc−dec); None for a
non-counter CRDT. This is how a counter reads as a plain number for Show and comparison.
Sourcepub fn insert(&mut self, value: &RuntimeValue) -> Result<(), String>
pub fn insert(&mut self, value: &RuntimeValue) -> Result<(), String>
Add element to <set> — insert into the observed-remove set.
Sourcepub fn remove(&mut self, value: &RuntimeValue) -> Result<(), String>
pub fn remove(&mut self, value: &RuntimeValue) -> Result<(), String>
Remove element from <set> / Remove key from <map> — observed-remove deletion.
Sourcepub fn contains(&self, value: &RuntimeValue) -> Result<bool, String>
pub fn contains(&self, value: &RuntimeValue) -> Result<bool, String>
<set> contains element / <map> contains key — observed-remove membership.
Sourcepub fn append(&mut self, value: &RuntimeValue) -> Result<(), String>
pub fn append(&mut self, value: &RuntimeValue) -> Result<(), String>
Append element to <sequence> — RGA append at the end.
Sourcepub fn resolve(&mut self, value: &RuntimeValue) -> Result<(), String>
pub fn resolve(&mut self, value: &RuntimeValue) -> Result<(), String>
Set <register> to value / Resolve <register> to value — the divergent register
takes a value that dominates all concurrent ones.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
length of <collection> — element count (set cardinality or sequence length).
pub fn is_empty(&self) -> bool
Sourcepub fn to_runtime_vec(&self) -> Vec<RuntimeValue>
pub fn to_runtime_vec(&self) -> Vec<RuntimeValue>
The elements as runtime values, in convergent order for a sequence and sorted for a set (sets have no intrinsic order — sorting makes the rendering deterministic).
Sourcepub fn register_value(&self) -> Option<RuntimeValue>
pub fn register_value(&self) -> Option<RuntimeValue>
The resolved value of a register — the single current value, or None while it is
empty or still divergent (multiple concurrent values).
Sourcepub fn merge(&mut self, other: &CrdtValue) -> Result<(), String>
pub fn merge(&mut self, other: &CrdtValue) -> Result<(), String>
Merge another CRDT of the SAME kind into this one (the convergent join). Mismatched kinds are a type error rather than a silent no-op.
Sourcepub fn version(&self) -> VClock
pub fn version(&self) -> VClock
The current causal version (vector clock) — every update this replica has observed. The
δ-CRDT mergeable send remembers the version it last shipped to a peer and ships only the
delta SINCE that version, so a large set/sequence syncs its few NEW entries, not its whole
state. Idempotent + commutative, so reordering or redelivering deltas still converges.
Sourcepub fn delta_since_bytes(&self, since: &VClock) -> Option<Vec<u8>>
pub fn delta_since_bytes(&self, since: &VClock) -> Option<Vec<u8>>
Serialize the changes since since as a KIND-TAGGED delta payload — far smaller than the
full state when little changed. None if the variant can’t produce a delta (history
truncated); the caller falls back to the full-state crdt_to_wire.
Sourcepub fn apply_delta_bytes(&mut self, bytes: &[u8]) -> bool
pub fn apply_delta_bytes(&mut self, bytes: &[u8]) -> bool
Apply a kind-tagged delta from delta_since_bytes of the SAME kind. Returns false on a
kind mismatch or malformed bytes, leaving self unchanged — a foreign / garbage delta never
corrupts the CRDT (the network-edge safety the mergeable receive needs).
Sourcepub fn to_full_state_bytes(&self) -> Vec<u8> ⓘ
pub fn to_full_state_bytes(&self) -> Vec<u8> ⓘ
Serialize the WHOLE convergent state as a KIND-TAGGED payload — the state-based delta since
the empty clock (every variant produces a valid full state at VClock::new()). This is what
crosses a task/Sync boundary: the far side rebuilds a fresh replica and MERGES it, so
re-applying the same bytes is idempotent. Distinct from crdt_to_wire (which projects a
counter to a plain-Int relay form); this preserves the FULL per-replica CRDT state.
Sourcepub fn from_full_state_bytes(bytes: &[u8]) -> CrdtValue
pub fn from_full_state_bytes(bytes: &[u8]) -> CrdtValue
Reconstruct a CRDT from to_full_state_bytes: build a FRESH empty replica of the tagged kind,
then apply the state (a per-replica merge). A malformed / empty payload degrades to a fresh
grow-only counter (the safe default for the counter-Sync path). The fresh replica id keeps
the rebuilt value from aliasing the sender’s live cell.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CrdtValue
impl RefUnwindSafe for CrdtValue
impl Send for CrdtValue
impl Sync for CrdtValue
impl Unpin for CrdtValue
impl UnsafeUnpin for CrdtValue
impl UnwindSafe for CrdtValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.