pub struct Document {
pub id: DocumentID,
pub fields: HashMap<FieldPath, Field>,
pub version: VectorClock,
}Expand description
A document with field-level LWW conflict resolution
Fields§
§id: DocumentIDUnique document identifier
fields: HashMap<FieldPath, Field>Document fields with LWW metadata
version: VectorClockVector clock for causality tracking
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(id: DocumentID) -> Self
pub fn new(id: DocumentID) -> Self
Create a new empty document
Sourcepub fn set_field(
&mut self,
field_path: FieldPath,
value: JsonValue,
clock: u64,
client_id: ClientID,
)
pub fn set_field( &mut self, field_path: FieldPath, value: JsonValue, clock: u64, client_id: ClientID, )
Set a field value (creates new timestamp)
This method uses LWW merge logic, so if there’s already a value with a newer timestamp, it won’t be overwritten.
Sourcepub fn merge_field(
&mut self,
field_path: FieldPath,
remote_field: Field,
) -> bool
pub fn merge_field( &mut self, field_path: FieldPath, remote_field: Field, ) -> bool
Merge a remote field using LWW algorithm
This is the core LWW merge algorithm verified by TLA+. Returns true if the local field was updated.
Comparison order:
- Higher timestamp wins
- If timestamps equal, higher client_id wins
- If both equal (duplicate), use value comparison for determinism
Sourcepub fn merge(&mut self, remote: &Document) -> usize
pub fn merge(&mut self, remote: &Document) -> usize
Merge an entire remote document
Merges all fields and vector clocks. Returns the number of fields updated.
Sourcepub fn field_paths(&self) -> Vec<&FieldPath> ⓘ
pub fn field_paths(&self) -> Vec<&FieldPath> ⓘ
Get all field paths
Sourcepub fn field_count(&self) -> usize
pub fn field_count(&self) -> usize
Get number of fields
Sourcepub fn id(&self) -> &DocumentID
pub fn id(&self) -> &DocumentID
Get document ID
Sourcepub fn version(&self) -> &VectorClock
pub fn version(&self) -> &VectorClock
Get document version (vector clock)
Sourcepub fn delete_field(&mut self, field_path: &FieldPath)
pub fn delete_field(&mut self, field_path: &FieldPath)
Delete a field
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
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
Mutably borrows from an owned value. Read more