Skip to main content

TextEditor

Struct TextEditor 

Source
pub struct TextEditor<'a> { /* private fields */ }
Expand description

A high-performance, transactional text editor.

It accumulates edits and applies them in a single pass when finish() is called. It ensures all edits are valid, non-overlapping, and safe according to optional user checks.

Implementations§

Source§

impl<'a> TextEditor<'a>

Source

pub fn new(text: &'a str) -> Self

Creates a new TextEditor with the default safety threshold (Unsafe - accepts all edits).

Source

pub fn with_safety(text: &'a str, threshold: Safety) -> Self

Creates a new TextEditor with a specific safety threshold.

Edits with a safety level above the threshold will be rejected.

§Example
use mago_text_edit::{TextEditor, Safety};

// Only accept Safe edits
let editor = TextEditor::with_safety("hello", Safety::Safe);
Source

pub fn apply<F>(&mut self, edit: TextEdit, checker: Option<F>) -> ApplyResult
where F: FnOnce(&str) -> bool,

Applies a single edit.

Uses binary search to check for overlaps in O(log N). Rejects edits that exceed the safety threshold.

Source

pub fn apply_batch<F>( &mut self, new_edits: Vec<TextEdit>, checker: Option<F>, ) -> ApplyResult
where F: FnOnce(&str) -> bool,

Applies a batch of edits atomically.

Either all edits are applied, or none are (if overlap/check/safety fails). If any edit in the batch exceeds the safety threshold, the entire batch is rejected.

Source

pub fn finish(self) -> String

Consumes the editor and returns the final modified string.

Source

pub fn get_edits(&self) -> &[TextEdit]

Returns a slice of the currently applied edits.

Source

pub fn safety_threshold(&self) -> Safety

Returns the current safety threshold.

Trait Implementations§

Source§

impl<'a> Clone for TextEditor<'a>

Source§

fn clone(&self) -> TextEditor<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for TextEditor<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for TextEditor<'a>

§

impl<'a> RefUnwindSafe for TextEditor<'a>

§

impl<'a> Send for TextEditor<'a>

§

impl<'a> Sync for TextEditor<'a>

§

impl<'a> Unpin for TextEditor<'a>

§

impl<'a> UnwindSafe for TextEditor<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.