DocumentReplica
struct · ferroui-designer-collaboration · v0.5.0
struct DocumentReplica
Ordered operation-set replication of a lossless XAML document. Property writes are last-writer wins in Lamport order; structural conflicts are explicit and resolved in that same order. A transaction arriving before its inserted-node dependency is retained and retried when the dependency arrives. No server order or wall-clock synchronization is required.
This is not a character-level text CRDT: arbitrary source replacements use exact-source CAS. Replay from the baseline provides deterministic structure even for concurrent cyclic moves.
Members
newactordocument_idbaseline_hashmessagedocumentsourceconflictsoperationsresolveshared_idrootversionhas_sequence_gapspending_operation_countchanges_sincechanges_since_boundedsnapshotfrom_snapshotmerge_snapshotsubmitset_attributeshared_id_insubmit_document_editsundo_propertymergereceive_presencepresenceprune_presence
new
fn new(actor: impl Into<String>, document_id: impl Into<String>, source: impl Into<String>) -> Result<Self>
actor
fn actor(self: &Self) -> &str
document_id
fn document_id(self: &Self) -> &str
baseline_hash
fn baseline_hash(self: &Self) -> &str
message
fn message(self: &Self, operations: Vec<Operation>) -> SyncMessage
document
fn document(self: &Self) -> &Document
source
fn source(self: &Self) -> &str
conflicts
fn conflicts(self: &Self) -> &[Conflict]
operations
fn operations(self: &Self) -> impl Iterator<Item = &Operation>
resolve
fn resolve(self: &Self, node: &SharedNodeId) -> Option<NodeId>
shared_id
fn shared_id(self: &Self, node: NodeId) -> Option<SharedNodeId>
root
fn root(self: &Self) -> SharedNodeId
version
fn version(self: &Self) -> VersionVector
has_sequence_gaps
fn has_sequence_gaps(self: &Self) -> bool
A contiguous vector is a complete checkpoint precondition only when every received operation is represented by it. A later operation beyond a hole must never be discarded merely because the visible contiguous prefix has not advanced.
pending_operation_count
fn pending_operation_count(self: &Self, version: &VersionVector, actor: &str) -> usize
Count an actor's outstanding writes without cloning source payloads into a wire message.
changes_since
fn changes_since(self: &Self, version: &VersionVector) -> SyncMessage
changes_since_bounded
fn changes_since_bounded(self: &Self, version: &VersionVector, actor: Option<&str>, max_bytes: usize) -> Result<SyncMessage>
Return one wire-sized page. Filter the writer before paging when uploading an outbox; otherwise other actors' already-acknowledged operations could consume the page. Continue with the receiving replica's updated version until no new operations remain. Only complete sender prefixes are paged: repeatedly sending a sequence beyond a hole could otherwise fill every page without advancing the receiver's vector.
snapshot
fn snapshot(self: &Self) -> Snapshot
from_snapshot
fn from_snapshot(actor: impl Into<String>, snapshot: Snapshot) -> Result<Self>
merge_snapshot
fn merge_snapshot(self: &mut Self, snapshot: Snapshot) -> Result<MergeReport>
submit
fn submit(self: &mut Self, label: impl Into<String>, edits: Vec<SharedEdit>) -> Result<Operation>
Submit an atomic local transaction, rejecting edits that cannot currently be applied. Hosts broadcast the returned operation; the new source is available via source().
set_attribute
fn set_attribute(self: &mut Self, node: SharedNodeId, name: impl Into<String>, value: impl Into<String>) -> Result<Operation>
shared_id_in
fn shared_id_in(self: &Self, document: &Document, node: NodeId) -> Result<SharedNodeId>
Resolve a node from an independently hosted document with byte-identical source. The host's local AST IDs may differ after undo or preview history; spans provide the bridge.
submit_document_edits
fn submit_document_edits(self: &mut Self, document: &Document, label: impl Into<String>, edits: Vec<Edit>) -> Result<Operation>
Convert existing designer commands to shared operations. Text-coordinate or whole-source edits intentionally become one source CAS operation; structured property/layout tools keep their fine-grained conflict semantics. Apply replica.source() to the host after success.
undo_property
fn undo_property(self: &mut Self, operation: &OperationId) -> Result<Operation>
Undo is a new causally later write. Conditional compensation refuses to overwrite another actor's change since the original operation. Structural undo can be supplied explicitly through submit(); no hidden mutation of the replicated operation log is allowed.
merge
fn merge(self: &mut Self, message: SyncMessage) -> Result<MergeReport>
Validates every envelope entry before changing the replica. Duplicate identity with different bytes is rejected as equivocation, never resolved by delivery order.
receive_presence
fn receive_presence(self: &mut Self, presence: Presence, now_millis: u64) -> Result<bool>
presence
fn presence(self: &Self, now_millis: u64, ttl_millis: u64) -> Vec<&Presence>
The receiving host's monotonic clock governs expiry, avoiding remote-clock assumptions.
prune_presence
fn prune_presence(self: &mut Self, now_millis: u64, ttl_millis: u64)
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedSameClone
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.