Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

Represents the current state of a document and all of its history

Implementations§

Source§

impl Engine

Source

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.

Source

pub fn empty() -> Engine

Source

pub fn max_undo_group_id(&self) -> usize

Returns the largest undo group ID used so far

Source

pub fn get_head_rev_id(&self) -> RevId

Get revision id of head revision.

Source

pub fn get_head(&self) -> &Rope

Get text of head revision.

Source

pub fn get_rev(&self, rev: RevToken) -> Option<Rope>

Get text of a given revision, if it can be found.

Source

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.

Source

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.

Source

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.

Source

pub fn undo(&mut self, groups: BTreeSet<usize>)

Source

pub fn is_equivalent_revision(&self, base_rev: RevId, other_rev: RevId) -> bool

Source

pub fn gc(&mut self, gc_groups: &BTreeSet<usize>)

Source

pub fn merge(&mut self, other: &Engine)

Merge the new content from another Engine into this one with a CRDT merge

Source

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.

Trait Implementations§

Source§

impl Debug for Engine

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Engine

§

impl RefUnwindSafe for Engine

§

impl Send for Engine

§

impl Sync for Engine

§

impl Unpin for Engine

§

impl UnwindSafe for Engine

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