Skip to main content

CrdtValue

Enum CrdtValue 

Source
pub enum CrdtValue {
    Set(ORSet<CrdtScalar>),
    SetRemoveWins(ORSet<CrdtScalar, RemoveWins>),
    Seq(RGA<CrdtScalar>),
    Register(MVRegister<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.

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 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> — observed-remove deletion.

Source

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

<set> contains element — 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 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 (const: unstable) · 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 + Sync + Send>

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,