Struct Engine
pub struct Engine { /* private fields */ }Expand description
Represents the current state of a document and all of its history
Implementations§
§impl Engine
impl Engine
pub fn new(initial_contents: Node<RopeInfo>) -> Engine
pub fn new(initial_contents: Node<RopeInfo>) -> 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
pub fn max_undo_group_id(&self) -> usize
pub fn max_undo_group_id(&self) -> usize
Returns the largest undo group ID used so far
pub fn get_head_rev_id(&self) -> RevId
pub fn get_head_rev_id(&self) -> RevId
Get revision id of head revision.
pub fn get_rev(&self, rev: u64) -> Option<Node<RopeInfo>>
pub fn get_rev(&self, rev: u64) -> Option<Node<RopeInfo>>
Get text of a given revision, if it can be found.
pub fn try_delta_rev_head(
&self,
base_rev: u64,
) -> Result<Delta<RopeInfo>, Error>
pub fn try_delta_rev_head( &self, base_rev: u64, ) -> 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.
pub fn edit_rev(
&mut self,
priority: usize,
undo_group: usize,
base_rev: u64,
delta: Delta<RopeInfo>,
)
pub fn edit_rev( &mut self, priority: usize, undo_group: usize, base_rev: u64, 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.
pub fn try_edit_rev(
&mut self,
priority: usize,
undo_group: usize,
base_rev: u64,
delta: Delta<RopeInfo>,
) -> Result<(), Error>
pub fn try_edit_rev( &mut self, priority: usize, undo_group: usize, base_rev: u64, 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>)
pub 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
pub fn set_session_id(&mut self, session: (u64, u32))
pub fn set_session_id(&mut self, session: (u64, u32))
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§
§impl<'de> Deserialize<'de> for Engine
impl<'de> Deserialize<'de> for Engine
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Engine, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Engine, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Serialize for Engine
impl Serialize for Engine
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for Engine
impl RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnsafeUnpin for Engine
impl UnwindSafe for Engine
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> DowncastSync for T
impl<T> DowncastSync for T
§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