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.
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.
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.
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.
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
impl CrdtType
Sourcepub fn lww_register(inner_type: impl Into<String>) -> CrdtType
pub fn lww_register(inner_type: impl Into<String>) -> CrdtType
Create an LwwRegister with a known inner type.
Sourcepub fn unordered_map(
key_type: impl Into<String>,
value_type: impl Into<String>,
) -> CrdtType
pub fn unordered_map( key_type: impl Into<String>, value_type: impl Into<String>, ) -> CrdtType
Create an UnorderedMap with known key and value types.
Sourcepub fn unordered_set(element_type: impl Into<String>) -> CrdtType
pub fn unordered_set(element_type: impl Into<String>) -> CrdtType
Create an UnorderedSet with a known element type.
Sourcepub fn vector(element_type: impl Into<String>) -> CrdtType
pub fn vector(element_type: impl Into<String>) -> CrdtType
Create a Vector with a known element type.
Sourcepub const fn is_counter(&self) -> bool
pub const fn is_counter(&self) -> bool
Returns true if this is a counter type (GCounter or PnCounter).
Sourcepub const fn is_collection(&self) -> bool
pub const fn is_collection(&self) -> bool
Returns true if this is a collection type (map, set, vector, or array).
Sourcepub const fn is_special_storage(&self) -> bool
pub const fn is_special_storage(&self) -> bool
Returns true if this type requires special storage handling.
Trait Implementations§
Source§impl BorshDeserialize for CrdtType
impl BorshDeserialize for CrdtType
fn deserialize_reader<__R>(reader: &mut __R) -> Result<CrdtType, Error>where
__R: Read,
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for CrdtType
impl BorshSerialize for CrdtType
Source§impl<'de> Deserialize<'de> for CrdtType
impl<'de> Deserialize<'de> for CrdtType
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<CrdtType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<CrdtType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Ord for CrdtType
impl Ord for CrdtType
Source§impl PartialOrd for CrdtType
impl PartialOrd for CrdtType
Source§impl Serialize for CrdtType
impl Serialize for CrdtType
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for CrdtType
impl StructuralPartialEq for CrdtType
Auto Trait Implementations§
impl Freeze for CrdtType
impl RefUnwindSafe for CrdtType
impl Send for CrdtType
impl Sync for CrdtType
impl Unpin for CrdtType
impl UnsafeUnpin for CrdtType
impl UnwindSafe for CrdtType
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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