Skip to main content

Engine

Struct Engine 

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

Synchronous, storage-neutral editor state machine.

Thread ownership: the host chooses the owning thread and must keep all mutable access on that thread. Engine does not create threads or invoke host callbacks.

Implementations§

Source§

impl Engine

Source

pub fn new() -> Self

Construct an empty engine using UUIDv7 undo-group identifiers.

Source

pub fn with_id_generator(ids: Box<dyn IdGenerator>) -> Self

Construct an empty engine with a host-provided identifier source.

Source

pub fn open_buffer(&mut self, text: &str) -> BufferId

Open text with a newly generated buffer identifier.

Source

pub fn load_buffer( &mut self, id: BufferId, text: &str, revision: Revision, ) -> BufferId

Load text under a host-provided id and revision.

Source

pub fn adopt_buffer(&mut self, buffer: Buffer) -> BufferId

Adopt a prepared buffer without performing persistence or I/O.

Source

pub fn close_buffer(&mut self, id: BufferId) -> Option<Buffer>

Remove a buffer and its transient engine state.

Source

pub fn snapshot(&self, id: BufferId) -> Option<EngineSnapshot>

Capture a buffer snapshot.

Source

pub fn text(&self, id: BufferId) -> Option<String>

Copy a buffer’s current text.

Source

pub fn selections(&self, id: BufferId) -> Option<&[Selection]>

Borrow a buffer’s current selections.

Source

pub fn revision(&self, id: BufferId) -> Option<Revision>

Return a buffer’s current revision.

Source

pub fn set_selections( &mut self, id: BufferId, selections: Vec<Selection>, ) -> Result<(), Error>

Replace and normalize a buffer’s selections.

Source

pub fn apply_edit( &mut self, id: BufferId, op: EditOp, timestamp_ms: i64, ) -> Result<ChangeBatch, Error>

Apply one raw atomic edit as a discrete undo group.

Source

pub fn apply_grouped_edit( &mut self, id: BufferId, ops: &[EditOp], selections_after: Vec<Selection>, command: &str, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Apply caller-planned operations as one discrete undo group.

Source

pub fn apply_selection_edit( &mut self, id: BufferId, edit: &SelectionEdit, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Plan and apply a selection-aware edit.

Source

pub fn undo( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Undo the current group.

Source

pub fn redo( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Replay the most-recent redo child.

Source

pub fn redo_alternate( &mut self, id: BufferId, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Replay an alternate redo branch.

Source

pub fn replace_text_if_revision( &mut self, id: BufferId, expected: Revision, text: impl Into<String>, timestamp_ms: i64, ) -> Result<ChangeBatch, Error>

Replace the full document only when the caller’s revision is current.

Source

pub fn reconcile_text_if_revision( &mut self, id: BufferId, expected: Revision, text: impl Into<String>, timestamp_ms: i64, ) -> Result<Option<ChangeBatch>, Error>

Reconcile a full host document when its expected revision is current.

Returns None when the supplied text already matches, so loading or reconciling current state never emits a phantom edit. A real difference is applied as the minimal single splice (shared prefix and suffix kept), so selections and host line mirrors outside the changed range stay put instead of collapsing to the document end.

Source

pub fn deltas_since( &self, id: BufferId, since_revision: u64, ) -> (Vec<RopeEditDelta>, bool)

Return byte deltas strictly newer than since_revision.

Source

pub fn deltas_with_points_since( &self, id: BufferId, since_revision: u64, ) -> (Vec<RopeEditDeltaWithPoints>, bool)

Return position-augmented deltas strictly newer than since_revision.

Source

pub fn drain_events(&mut self) -> Vec<EngineEvent>

Drain events emitted since the previous call.

Source

pub fn state(&self) -> &EngineState

Borrow the lower-level state for native host queries during migration.

Source

pub fn state_mut(&mut self) -> &mut EngineState

Mutably borrow lower-level state for native host-only metadata changes.

Trait Implementations§

Source§

impl Default for Engine

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Engine

§

impl !Send for Engine

§

impl !Sync for Engine

§

impl !UnwindSafe for Engine

§

impl Forget for Engine

§

impl Freeze for Engine

§

impl Move for Engine

§

impl Unpin for Engine

§

impl UnsafeUnpin 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.