Struct State
pub struct State {
pub doc: AutoCommit,
pub root: ExId,
/* private fields */
}Expand description
The unified state object that holds our CRDT document.
Fields§
§doc: AutoCommit§root: ExIdImplementations§
§impl State
impl State
pub fn new() -> State
pub fn adopt_doc(&mut self, doc: AutoCommit) -> bool
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.
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 history_revision(&self) -> u64
pub fn history_revision(&self) -> u64
A counter that changes whenever this document’s history does. See
UndoLog::revision.
pub fn commit_action(
&mut self,
focused_node_idx: Option<usize>,
metadata: Option<String>,
)
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.
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 peek_last_undo(&self) -> Option<UndoEntry>
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
pub fn undo_depth(&self) -> usize
How many steps of this session are in effect. See
UndoLog::undo_depth.
pub fn can_undo_as(&self, author: Option<&UserId>) -> bool
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(&self, author: Option<&UserId>) -> UndoStatus
pub fn undo_status(&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 what each step’s action record says it did
([crate::undo::step_summary]), the sentence its history row reads,
so a control and the timeline describe an action the same way.
pub fn record_committed_action(
&mut self,
before: Vec<ChangeHash>,
focused_node_idx: Option<usize>,
metadata: Option<String>,
) -> bool
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.
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
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 undo(
&mut self,
current_focused_idx: Option<usize>,
current_metadata: Option<String>,
) -> Option<UndoEntry>
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>,
) -> Option<UndoEntry>
pub fn undo_as( &mut self, author: Option<&UserId>, current_focused_idx: Option<usize>, current_metadata: Option<String>, ) -> 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.
pub fn redo_as(
&mut self,
author: Option<&UserId>,
current_focused_idx: Option<usize>,
current_metadata: Option<String>,
) -> Option<UndoEntry>
pub fn redo_as( &mut self, author: Option<&UserId>, current_focused_idx: Option<usize>, current_metadata: Option<String>, ) -> 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>
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 from_doc(doc: AutoCommit) -> State
pub fn from_doc(doc: AutoCommit) -> State
Wrap an already-loaded document.
The entry point for persistence: 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>
pub fn load(data: &[u8]) -> Result<State, AutomergeError>
Restores an application state from a serialized byte vector.
pub fn load_incremental(&mut self, data: &[u8]) -> Result<usize, AutomergeError>
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).
A payload that stops parsing part way is refused whole: none of its
changes are applied, not even the ones before the corruption.
pub fn merge_snapshot(&mut self, data: &[u8]) -> Result<(), AutomergeError>
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>)
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)
pub fn rebase_outbound(&mut self)
Reset the primary route after an address/record change.
pub fn save_incremental(&mut self) -> Vec<u8> ⓘ
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§
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> 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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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