Skip to main content

CrdtType

Enum CrdtType 

Source
pub enum CrdtType {
    LwwRegister {
        inner_type: String,
    },
    GCounter,
    PnCounter,
    Rga,
    UnorderedMap {
        key_type: String,
        value_type: String,
    },
    UnorderedSet {
        element_type: String,
    },
    Vector {
        element_type: String,
    },
    UserStorage,
    FrozenStorage,
    Custom(String),
}
Expand description

CRDT type indicator for merge semantics.

Identifies the conflict resolution strategy used when merging replicated data. This enum is used both by the storage layer (for persistence metadata) and the sync protocol (for wire-format entity classification).

§Merge Semantics

Each variant defines specific merge behavior:

  • Registers: LwwRegister (timestamp-based)
  • Counters: GCounter (grow-only), PnCounter (increment/decrement)
  • Collections: Rga, UnorderedMap, UnorderedSet, Vector
  • Special: UserStorage, FrozenStorage, Custom

Variants§

§

LwwRegister

Last-Writer-Wins Register.

Wraps primitive types with timestamp-based conflict resolution. Merge: Higher HLC timestamp wins, with node ID as tie-breaker.

The inner type name enables proper deserialization during merge.

Fields

§inner_type: String

Inner type name (e.g., “String”, “u64”, “MyStruct”)

§

GCounter

Grow-only Counter.

Supports only increment operations; value can never decrease. Internally tracks increments per executor. Merge: Take maximum of each executor’s count.

§

PnCounter

Positive-Negative Counter.

Supports both increment and decrement operations. Internally uses two maps: positive and negative counts per executor. Merge: Union of positive maps, union of negative maps, then compute difference.

§

Rga

Replicated Growable Array.

CRDT for collaborative text editing and ordered sequences. Supports concurrent insertions and deletions with causal ordering. Merge: Interleave elements by (timestamp, node_id) ordering.

§

UnorderedMap

Unordered Map.

Key-value store with add-wins semantics for keys. Keys are never lost once added (tombstoned but retained). Values are merged recursively if they implement Mergeable. Merge: Union of keys, recursive merge of values.

Fields

§key_type: String

Key type name

§value_type: String

Value type name (may be a nested CRDT)

§

UnorderedSet

Unordered Set.

Collection of unique values with add-wins semantics. Elements are never lost once added. Merge: Union of all elements from both sets.

Fields

§element_type: String

Element type name

§

Vector

Vector (ordered collection).

Ordered list with append operations. Elements are identified by index + timestamp for ordering. Merge: Element-wise merge by index with timestamp ordering.

Fields

§element_type: String

Element type name (may be a nested CRDT)

§

UserStorage

User Storage.

Per-user data storage with signature-based access control. Only the owning user (identified by executor ID) can modify their data. Merge: Latest update per user based on nonce/timestamp.

§

FrozenStorage

Frozen Storage.

Write-once storage for immutable data. Data can be written once and never modified or deleted. Merge: First-write-wins (subsequent writes are no-ops).

§

Custom(String)

Custom CRDT with app-defined merge.

For types annotated with #[derive(CrdtState)] that define custom merge logic. The string identifies the custom type name within the application. Merge: Dispatched to WASM runtime to call the app’s merge function.

Implementations§

Source§

impl CrdtType

Source

pub fn lww_register(inner_type: impl Into<String>) -> CrdtType

Create an LwwRegister with a known inner type.

Source

pub fn unordered_map( key_type: impl Into<String>, value_type: impl Into<String>, ) -> CrdtType

Create an UnorderedMap with known key and value types.

Source

pub fn unordered_set(element_type: impl Into<String>) -> CrdtType

Create an UnorderedSet with a known element type.

Source

pub fn vector(element_type: impl Into<String>) -> CrdtType

Create a Vector with a known element type.

Source

pub const fn is_counter(&self) -> bool

Returns true if this is a counter type (GCounter or PnCounter).

Source

pub const fn is_set(&self) -> bool

Returns true if this is a set type.

Source

pub const fn is_collection(&self) -> bool

Returns true if this is a collection type (map, set, vector, or array).

Source

pub const fn is_custom(&self) -> bool

Returns true if this is a custom CRDT type.

Source

pub const fn is_special_storage(&self) -> bool

Returns true if this type requires special storage handling.

Trait Implementations§

Source§

impl BorshDeserialize for CrdtType

Source§

fn deserialize_reader<__R>(reader: &mut __R) -> Result<CrdtType, Error>
where __R: Read,

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for CrdtType

Source§

fn serialize<__W>(&self, writer: &mut __W) -> Result<(), Error>
where __W: Write,

Source§

impl Clone for CrdtType

Source§

fn clone(&self) -> CrdtType

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 CrdtType

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for CrdtType

Source§

fn default() -> CrdtType

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CrdtType

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<CrdtType, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl EnumExt for CrdtType

Source§

fn deserialize_variant<__R>( reader: &mut __R, variant_tag: u8, ) -> Result<CrdtType, Error>
where __R: Read,

Deserialises given variant of an enum from the reader. Read more
Source§

impl Ord for CrdtType

Source§

fn cmp(&self, other: &CrdtType) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for CrdtType

Source§

fn eq(&self, other: &CrdtType) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for CrdtType

Source§

fn partial_cmp(&self, other: &CrdtType) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for CrdtType

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for CrdtType

Source§

impl StructuralPartialEq for CrdtType

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
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Reflect for T

Source§

fn as_dyn_ref<'a>(&self) -> &(dyn Reflect + 'a)
where T: 'a,

Source§

fn as_dyn_mut<'a>(&mut self) -> &mut (dyn Reflect + 'a)
where T: 'a,

Source§

fn as_dyn_box<'a>(self: Box<T>) -> Box<dyn Reflect + 'a>
where T: 'a,

Source§

fn as_dyn_rc<'a>(self: Rc<T>) -> Rc<dyn Reflect + 'a>
where T: 'a,

Source§

fn as_dyn_arc<'a>(self: Arc<T>) -> Arc<dyn Reflect + 'a>
where T: 'a,

Source§

fn type_id(&self) -> TypeId

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> ReflectExt for T
where T: Reflect + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: Reflect + ?Sized,

Source§

fn type_id() -> TypeId

Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: Reflect,

Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: Reflect,

Source§

fn downcast_box<T>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
where T: Reflect,

Source§

fn downcast_rc<T>(self: Rc<Self>) -> Result<Rc<T>, Rc<Self>>
where T: Reflect,

Source§

fn downcast_arc<T>(self: Arc<Self>) -> Result<Arc<T>, Arc<Self>>
where T: Reflect,

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,