pub enum Value {
Null,
Bool(bool),
Int(i64),
Text(String),
Doc(Doc),
List(List),
Deleted,
}Expand description
Values that can be stored in CRDT documents.
Value represents all possible data types that can be stored within
a CRDT document structure. Values can be either leaf values (terminal data)
or branch values (containing other structures).
§Value Types
§Leaf Values (Terminal Nodes)
Value::Null- Represents null/empty valuesValue::Bool- Boolean values (true/false)Value::Int- 64-bit signed integersValue::Text- UTF-8 text strings
§Branch Values (Container Nodes)
Value::Doc- Nested document structuresValue::List- Ordered collections with stable positioning
§CRDT Semantics
Value::Deleted- Tombstone marker for deleted values
§Direct Comparisons
Value implements PartialEq with primitive types for ergonomic comparisons:
let text = Value::Text("hello".to_string());
let number = Value::Int(42);
let flag = Value::Bool(true);
// Direct comparison with primitives
assert!(text == "hello");
assert!(number == 42);
assert!(flag == true);
// Reverse comparisons also work
assert!("hello" == text);
assert!(42 == number);
assert!(true == flag);
// Type mismatches return false
assert!(!(text == 42));
assert!(!(number == "hello"));§CRDT Merge Behavior
- Leaf values: Last-write-wins semantics
- Branch values: Structural merging (recursive for Doc, positional for List)
- Tombstones: Deletion markers that win over any non-deleted value
- Resurrection: Non-deleted values can overwrite tombstones
let mut val1 = Value::Int(42);
let val2 = Value::Int(100);
val1.merge(&val2); // val1 becomes 100 (last-write-wins)
let mut val3 = Value::Text("hello".to_string());
let deleted = Value::Deleted;
val3.merge(&deleted); // val3 becomes Deleted (tombstone wins)Variants§
Null
Null/empty value
Bool(bool)
Boolean value
Int(i64)
Integer value
Text(String)
Text string value
Doc(Doc)
Sub-tree containing other nodes
List(List)
Ordered collection of values
Deleted
Tombstone marker for deleted values
Implementations§
Source§impl Value
impl Value
Sourcepub fn is_branch(&self) -> bool
pub fn is_branch(&self) -> bool
Returns true if this is a branch value (can contain other nodes)
Sourcepub fn is_deleted(&self) -> bool
pub fn is_deleted(&self) -> bool
Returns true if this value represents a deletion
Sourcepub fn as_bool_or(&self, default: bool) -> bool
pub fn as_bool_or(&self, default: bool) -> bool
Attempts to convert to a boolean, returning default if not a bool
Sourcepub fn as_bool_or_false(&self) -> bool
pub fn as_bool_or_false(&self) -> bool
Attempts to convert to a boolean, returning false if not a bool
Sourcepub fn as_int_or(&self, default: i64) -> i64
pub fn as_int_or(&self, default: i64) -> i64
Attempts to convert to an integer, returning default if not an int
Sourcepub fn as_int_or_zero(&self) -> i64
pub fn as_int_or_zero(&self) -> i64
Attempts to convert to an integer, returning 0 if not an int
Sourcepub fn as_text_or_empty(&self) -> &str
pub fn as_text_or_empty(&self) -> &str
Attempts to convert to a string, returning empty string if not text
Sourcepub fn as_doc(&self) -> Option<&Doc>
pub fn as_doc(&self) -> Option<&Doc>
Attempts to convert to a Doc (returns immutable reference)
Sourcepub fn as_doc_mut(&mut self) -> Option<&mut Doc>
pub fn as_doc_mut(&mut self) -> Option<&mut Doc>
Attempts to convert to a mutable Doc reference
Sourcepub fn as_list(&self) -> Option<&List>
pub fn as_list(&self) -> Option<&List>
Attempts to convert to a list (returns immutable reference)
Sourcepub fn as_list_mut(&mut self) -> Option<&mut List>
pub fn as_list_mut(&mut self) -> Option<&mut List>
Attempts to convert to a mutable list reference
Sourcepub fn merge(&mut self, other: &Value)
pub fn merge(&mut self, other: &Value)
Merges another Value into this one (CRDT merge operation)
Sourcepub fn to_json_string(&self) -> String
pub fn to_json_string(&self) -> String
Converts to a JSON-like string representation for human-readable output.
This method produces clean JSON output intended for display, debugging, and export. It differs from serde serialization in important ways:
- Tombstones: Deleted values appear as
nullinstead of being preserved as tombstones - Purpose: Human-readable output, not CRDT state preservation
- Use cases: Display, debugging, export to external systems
For complete CRDT state preservation including tombstones, use serde serialization instead.
§Examples
let value = Value::Text("hello".to_string());
assert_eq!(value.to_json_string(), "\"hello\"");
let deleted = Value::Deleted;
assert_eq!(deleted.to_json_string(), "null"); // Tombstones become nullTrait Implementations§
Source§impl<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<DelegatedTreeRef> for Value
impl From<DelegatedTreeRef> for Value
Source§fn from(dtref: DelegatedTreeRef) -> Value
fn from(dtref: DelegatedTreeRef) -> Value
Source§impl From<Permission> for Value
impl From<Permission> for Value
Source§fn from(perm: Permission) -> Value
fn from(perm: Permission) -> Value
Source§impl From<PermissionBounds> for Value
impl From<PermissionBounds> for Value
Source§fn from(bounds: PermissionBounds) -> Value
fn from(bounds: PermissionBounds) -> Value
Source§impl From<TreeReference> for Value
impl From<TreeReference> for Value
Source§fn from(tree_ref: TreeReference) -> Value
fn from(tree_ref: TreeReference) -> Value
Source§impl FromIterator<Value> for List
impl FromIterator<Value> for List
impl Data for Value
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
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> CompatExt for T
impl<T> CompatExt for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.