pub struct Engine { /* private fields */ }Expand description
Represents the current state of a document and all of its history
Implementations§
Source§impl Engine
impl Engine
Sourcepub fn new(initial_contents: Rope) -> Engine
pub fn new(initial_contents: Rope) -> Engine
Create a new Engine with a single edit that inserts initial_contents
if it is non-empty. It needs to be a separate commit rather than just
part of the initial contents since any two Engines need a common
ancestor in order to be mergeable.
pub fn empty() -> Engine
Sourcepub fn max_undo_group_id(&self) -> usize
pub fn max_undo_group_id(&self) -> usize
Returns the largest undo group ID used so far
Sourcepub fn get_head_rev_id(&self) -> RevId
pub fn get_head_rev_id(&self) -> RevId
Get revision id of head revision.
Sourcepub fn get_rev(&self, rev: RevToken) -> Option<Rope>
pub fn get_rev(&self, rev: RevToken) -> Option<Rope>
Get text of a given revision, if it can be found.
Sourcepub fn try_delta_rev_head(
&self,
base_rev: RevToken,
) -> Result<Delta<RopeInfo>, Error>
pub fn try_delta_rev_head( &self, base_rev: RevToken, ) -> Result<Delta<RopeInfo>, Error>
A delta that, when applied to base_rev, results in the current head. Returns
an error if there is not at least one edit.
Sourcepub fn edit_rev(
&mut self,
priority: usize,
undo_group: usize,
base_rev: RevToken,
delta: Delta<RopeInfo>,
)
pub fn edit_rev( &mut self, priority: usize, undo_group: usize, base_rev: RevToken, delta: Delta<RopeInfo>, )
Create a new edit based on base_rev.
§Panics
Panics if base_rev does not exist, or if delta is poorly formed.
Sourcepub fn try_edit_rev(
&mut self,
priority: usize,
undo_group: usize,
base_rev: RevToken,
delta: Delta<RopeInfo>,
) -> Result<(), Error>
pub fn try_edit_rev( &mut self, priority: usize, undo_group: usize, base_rev: RevToken, delta: Delta<RopeInfo>, ) -> Result<(), Error>
Attempts to apply a new edit based on the [Revision] specified by base_rev,
Returning an Error if the Revision cannot be found.
pub fn undo(&mut self, groups: BTreeSet<usize>)
pub fn is_equivalent_revision(&self, base_rev: RevId, other_rev: RevId) -> bool
pub fn gc(&mut self, gc_groups: &BTreeSet<usize>)
Sourcepub fn merge(&mut self, other: &Engine)
pub fn merge(&mut self, other: &Engine)
Merge the new content from another Engine into this one with a CRDT merge
Sourcepub fn set_session_id(&mut self, session: SessionId)
pub fn set_session_id(&mut self, session: SessionId)
When merging between multiple concurrently-editing sessions, each session should have a unique ID set with this function, which will make the revisions they create not have colliding IDs. For safety, this will panic if any revisions have already been added to the Engine.
Merge may panic or return incorrect results if session IDs collide, which is why they can be 96 bits which is more than sufficient for this to never happen.