pub struct MultiNodeState { /* private fields */ }Expand description
A document’s CRDT merge state split into one independent Yrs state per
top-level node — the durable per-node base of #qnodemerge2.
The legacy whole-doc <hash>.yrs blob reconciles every node against one
shared base, so a node’s base can never advance independently and unrelated
edits share a single Yrs clock. MultiNodeState instead persists one Yrs
state per node (each agent:* component plus the interstitial text around
them) in document order, serialized into a single structured container file
(<hash>.nodes.yrs). Each node therefore carries its own stable base across
cycles: a node untouched this cycle re-encodes to byte-identical state while a
changed node’s state advances on its own, with no cross-node contention.
Implementations§
Source§impl MultiNodeState
impl MultiNodeState
Sourcepub fn from_text(text: &str) -> Result<Self>
pub fn from_text(text: &str) -> Result<Self>
Build a per-node state by segmenting text into top-level nodes and
encoding each node’s text as its own independent Yrs state.
Sourcepub fn to_text(&self) -> Result<String>
pub fn to_text(&self) -> Result<String>
Reconstruct the full document text by concatenating node texts in order.
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Serialize into the <hash>.nodes.yrs container format:
MAGIC(4) | version(1) | node_count(u32 LE) then per node
name_len(u32 LE) | name bytes | state_len(u32 LE) | state bytes,
where name_len == u32::MAX marks an interstitial node (no name).
Sourcepub fn decode(bytes: &[u8]) -> Result<Self>
pub fn decode(bytes: &[u8]) -> Result<Self>
Decode a <hash>.nodes.yrs container. Returns an error (never a panic) on
a missing magic tag or any truncation, so callers can fall back to
migration via MultiNodeState::decode_or_migrate.
Sourcepub fn decode_or_migrate(bytes: &[u8], fallback_text: &str) -> Self
pub fn decode_or_migrate(bytes: &[u8], fallback_text: &str) -> Self
Decode bytes as a per-node container, migrating older formats:
- A
<hash>.nodes.yrscontainer decodes directly. - Otherwise treat
bytesas a legacy whole-doc<hash>.yrsYrs state, decode it to text, and split into per-node states. - If neither works, fall back to
fallback_text.
Never panics; logs the migration path it took.
Sourcepub fn merge(
base: Option<&MultiNodeState>,
ours_text: &str,
theirs_text: &str,
) -> Result<(String, MultiNodeState)>
pub fn merge( base: Option<&MultiNodeState>, ours_text: &str, theirs_text: &str, ) -> Result<(String, MultiNodeState)>
Per-node component-scoped three-way merge (#qnodemerge2).
Like merge_by_component but each node reconciles against its own
persisted base (carried in base) rather than a slice of one decoded
whole-doc base, and the merged result is returned as a fresh
MultiNodeState where each node’s base has advanced independently. An
unchanged node re-encodes to byte-identical state.
Falls back to the whole-document merge (against base’s projected
text) on structural divergence or a component-less document, preserving
the same safety net as merge_by_component.
Trait Implementations§
Source§impl Clone for MultiNodeState
impl Clone for MultiNodeState
Source§impl Debug for MultiNodeState
impl Debug for MultiNodeState
Source§impl Default for MultiNodeState
impl Default for MultiNodeState
impl Eq for MultiNodeState
Source§impl PartialEq for MultiNodeState
impl PartialEq for MultiNodeState
impl StructuralPartialEq for MultiNodeState
Auto Trait Implementations§
impl Forget for MultiNodeState
impl Freeze for MultiNodeState
impl RefUnwindSafe for MultiNodeState
impl Send for MultiNodeState
impl Sync for MultiNodeState
impl Unpin for MultiNodeState
impl UnsafeUnpin for MultiNodeState
impl UnwindSafe for MultiNodeState
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> 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§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.