Skip to main content

MultiNodeState

Struct MultiNodeState 

Source
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

Source

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.

Source

pub fn to_text(&self) -> Result<String>

Reconstruct the full document text by concatenating node texts in order.

Source

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).

Source

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.

Source

pub fn decode_or_migrate(bytes: &[u8], fallback_text: &str) -> Self

Decode bytes as a per-node container, migrating older formats:

  1. A <hash>.nodes.yrs container decodes directly.
  2. Otherwise treat bytes as a legacy whole-doc <hash>.yrs Yrs state, decode it to text, and split into per-node states.
  3. If neither works, fall back to fallback_text.

Never panics; logs the migration path it took.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MultiNodeState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MultiNodeState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for MultiNodeState

Source§

impl PartialEq for MultiNodeState

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for MultiNodeState

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<M> Meta for M
where M: Default,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.