Skip to main content

State

Struct State 

pub struct State {
    pub collab: CollaborationState,
    pub doc: AutoCommit,
    pub root: ExId,
    /* private fields */
}
Expand description

The unified state object that holds our CRDT document.

Fields§

§collab: CollaborationState

Compatibility cursor surface; modern collaboration uses PresenceCtx.

§doc: AutoCommit§root: ExId

Implementations§

§

impl State

pub fn diagnostics(&mut self) -> DocumentDiagnostics

Metadata-only snapshot suitable for support bundles and JSON tooling. Reading it commits no transaction and advances no serialization cursor.

§

impl State

pub fn new() -> State

pub fn adopt_doc(&mut self, doc: AutoCommit) -> bool

Replace the live document with another one — a different record’s.

The undo history goes with it: an UndoEntry is a pair of change hashes in this document’s graph, and carried across a swap it would name changes the new document has never seen. Each record’s history is its own, so the stacks reset rather than travel.

collab (remote cursors and presence) is kept: presence is about who else is here, which does not change because the document on screen did. Returns false when the history revision namespace is exhausted. In that case the live document is deliberately left in place: adopting a new one under an indistinguishable revision could reuse cached history UI from the old document.

pub fn document_identity(&self) -> Uuid

The lifetime of the currently adopted document. Commit, undo, merge and save keep it stable; successful adopt_doc changes it even for identical bytes. Replace documents through adopt_doc, not direct field assignment.

pub fn history_mut(&mut self) -> &mut UndoLog

This document’s history, for a caller that drives undo itself.

pub fn history_revision(&self) -> u64

A counter that changes whenever this document’s history does. See UndoLog::revision.

pub fn revision_history(&mut self) -> RevisionHistory

Reconstruct the document’s persistent causal history, including branches and merges. No app-defined history schema is required.

pub fn restore_revision( &mut self, revision: RevisionId, focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, ) -> Result<bool, UnknownRevision>

Restore the content at one persistent revision as a new forward, undoable change. The old branch remains in Self::revision_history.

§Errors

Returns UnknownRevision when revision belongs to another document or is otherwise absent from this document’s change graph.

pub fn commit_action( &mut self, focused_node_idx: Option<usize>, metadata: Option<String>, )

Commit the current transaction and push a change-based undo entry recording the heads that bracket this action.

pub fn commit_action_authored( &mut self, focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, ) -> bool

Commit the current transaction and push a change-based undo entry, attributing it to author so multi-user undo can isolate users. Returns true iff a change was committed (see the UndoLog method).

pub fn commit_action_authored_with_context( &mut self, focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, context: Option<ActionContext>, ) -> bool

pub fn peek_last_undo(&self) -> Option<UndoEntry>

The newest step of this session still in effect, without taking it back.

pub fn undo_depth(&self) -> usize

How many steps of this session are in effect. See UndoLog::undo_depth.

pub fn redo_depth(&self) -> usize

How many undos of this session redo can bring back. See UndoLog::redo_depth.

pub fn can_undo_as(&self, author: Option<&UserId>) -> bool

Whether author has anything to undo / redo. See UndoLog::can_undo_as.

pub fn can_redo_as(&self, author: Option<&UserId>) -> bool

pub fn undo_status(&mut self, author: Option<&UserId>) -> UndoStatus

What the history can do for author right now, ready to hand to a widget — see UndoStatus.

The summaries are derived from the bracketed changes themselves through history_source::change_summary, the same producer the history pane uses, so a control and the timeline describe an action the same way. Both read “the action, as performed”: an undo entry brackets before → after, while a redo entry holds the inverse change, so its summary reads after → before.

pub fn record_committed_action( &mut self, before: Vec<ChangeHash>, focused_node_idx: Option<usize>, metadata: Option<String>, ) -> bool

Record an action that has already been committed into doc out-of-band (e.g. a tilo_actions action the Ctrl+K palette dispatched, which owns its own actor + timestamp commit boundary). Brackets the undo entry with the caller-supplied before heads, clears the redo stack, and realigns the undo baseline.

pub fn record_committed_action_authored( &mut self, before: Vec<ChangeHash>, focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, ) -> bool

As Self::record_committed_action, naming who performed it — for a change that reached this document from outside the window. See UndoLog::record_committed_action_authored.

pub fn restore_to_heads( &mut self, target_heads: &[ChangeHash], focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, ) -> bool

Rewrite the document to the content it had at target_heads, as a NEW forward change — “restore to this version” from the history scrubber. Takes the same route as undo: derive the patches from current to target, then write them, so history is appended to, never rewritten.

Consequences: the restore shows up in the timeline as its own entry (the versions it rolled past are still there); remote edits merged in while scrubbing survive, since only what actually differs is rewritten; and the restore is itself undoable.

Returns true when something changed; a restore to the current state is a no-op.

pub fn restore_to_heads_with_context( &mut self, target_heads: &[ChangeHash], focused_node_idx: Option<usize>, metadata: Option<String>, author: Option<UserId>, context: &ActionContext, ) -> bool

Self::restore_to_heads, stamping the restore change with context so History names it rather than describing its raw patch set.

pub fn undo( &mut self, current_focused_idx: Option<usize>, current_metadata: Option<String>, ) -> Option<UndoEntry>

Undo the most recent action by writing its inverse as a new forward change. Callers pass the current focus index and widget metadata so the redo entry carries the caret/focus state at the moment undo fired — otherwise Ctrl+Shift+Z would rehydrate the text body but leave the caret at offset 0.

pub fn undo_as( &mut self, author: Option<&UserId>, current_focused_idx: Option<usize>, current_metadata: Option<String>, registry: Option<&ActionRegistry>, ) -> Option<UndoEntry>

Undo on behalf of author: the entry point every interactive Ctrl+Z takes. With an author, undo skips past other people’s actions, so one collaborator never reverts another’s work; None — an app running with no identity at all — keeps the plain LIFO behaviour. With registry, a step that queued an outside consequence is taken back through its verified inverse action.

pub fn redo_as( &mut self, author: Option<&UserId>, current_focused_idx: Option<usize>, current_metadata: Option<String>, registry: Option<&ActionRegistry>, ) -> Option<UndoEntry>

Redo on behalf of author — the mirror of Self::undo_as, so a redo cannot re-apply an action the local user never undid.

pub fn redo( &mut self, current_focused_idx: Option<usize>, current_metadata: Option<String>, ) -> Option<UndoEntry>

Redo the most recently undone action by inverting the inverse change (re-applying the original action’s delta as a new forward change). current_focused_idx / current_metadata are captured on the undo stack so a subsequent undo can park the caret back where it was pre-redo.

pub fn save(&mut self) -> Vec<u8> ⓘ

Serializes the entire application CRDT state into a byte vector.

pub fn from_doc(doc: AutoCommit) -> State

Wrap an already-loaded document.

The entry point for persistence (tilo_ui::persist): the store hands back the previous session’s AutoCommit — history, actor identity and all — and this adopts it as the live document without a byte round-trip.

pub fn load(data: &[u8]) -> Result<State, AutomergeError>

Restores an application state from a serialized byte vector.

§Errors

Returns an error if data is not a valid Automerge document (corrupt bytes, or bytes produced by an incompatible format).

pub fn load_incremental(&mut self, data: &[u8]) -> Result<usize, AutomergeError>

Apply an incremental CRDT patch (bytes produced by AutoCommit::save_incremental on another peer) into this document. Returns the number of ops applied on success.

This is how an incremental CollabEvent::Document is merged on the receiver side — without it, incremental deltas broadcast by one peer would never reach another peer’s CRDT.

§Errors

Returns an error if data is not a valid incremental Automerge patch (corrupt bytes, or bytes that don’t apply to this document’s history).

pub fn merge_snapshot(&mut self, data: &[u8]) -> Result<(), AutomergeError>

Merge a complete peer snapshot without replacing local work, then atomically align undo and outbound frontiers with the merged graph.

§Errors

Returns an error when data is not a valid Automerge snapshot or cannot be merged into this document.

pub fn pending_outbound_delta(&mut self) -> (Vec<u8>, Vec<ChangeHash>)

Prepare primary-route bytes without advancing its frontier. The caller advances only after its durable queue accepts the payload.

pub fn advance_outbound(&mut self, heads: Vec<ChangeHash>)

pub fn rebase_outbound(&mut self)

Reset the primary route after an address/record change.

pub fn save_incremental(&mut self) -> Vec<u8> ⓘ

Serialize the changes made since the last save/save_incremental call. The returned bytes can be fed into another peer’s load_incremental to replay just the delta — the basic building block of efficient CRDT sync.

Trait Implementations§

§

impl Default for State

§

fn default() -> State

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

Auto Trait Implementations§

§

impl !Freeze for State

§

impl !RefUnwindSafe for State

§

impl !Send for State

§

impl !Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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> NoneValue for T
where T: Default,

§

type NoneType = T

§

fn null_value() -> T

The none-equivalent value.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,