Skip to main content

CrdtValue

Enum CrdtValue 

Source
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

Source

pub fn new_set(replica: ReplicaId) -> CrdtValue

Source

pub fn new_set_remove_wins(replica: ReplicaId) -> CrdtValue

Source

pub fn new_seq(replica: ReplicaId) -> CrdtValue

Source

pub fn new_register(replica: ReplicaId) -> CrdtValue

Source

pub fn new_counter(replica: ReplicaId) -> CrdtValue

Source

pub fn new_pn_counter(replica: ReplicaId) -> CrdtValue

Source

pub fn new_map(replica: ReplicaId) -> CrdtValue

Source

pub fn map_put( &mut self, key: &RuntimeValue, value: &RuntimeValue, ) -> Result<(), String>

Set <map>[key] to value.

Source

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.

Source

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.

Source

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.

Source

pub fn crdt_kind(&self) -> CrdtKind

Which CRDT this is.

Source

pub fn kind(&self) -> &'static str

The CRDT kind, used for type errors and type_name.

Source

pub fn insert(&mut self, value: &RuntimeValue) -> Result<(), String>

Add element to <set> — insert into the observed-remove set.

Source

pub fn remove(&mut self, value: &RuntimeValue) -> Result<(), String>

Remove element from <set> / Remove key from <map> — observed-remove deletion.

Source

pub fn contains(&self, value: &RuntimeValue) -> Result<bool, String>

<set> contains element / <map> contains key — observed-remove membership.

Source

pub fn append(&mut self, value: &RuntimeValue) -> Result<(), String>

Append element to <sequence> — RGA append at the end.

Source

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.

Source

pub fn len(&self) -> usize

length of <collection> — element count (set cardinality or sequence length).

Source

pub fn is_empty(&self) -> bool

Source

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).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

pub fn render(&self) -> String

Show rendering: a set renders in set notation {…} (matching a plain Set), a sequence as an ordered list […], a register as its resolved value (or, while still divergent, the brace-joined set of concurrent values).

Trait Implementations§

Source§

impl Clone for CrdtValue

Source§

fn clone(&self) -> CrdtValue

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CrdtValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,