Skip to main content

TextRope

Struct TextRope 

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

Balanced B-Tree Rope text data structure for logarithmic-time line indexing, splitting, joining, and editing across massive documents (100,000+ lines).

Implementations§

Source§

impl TextRope

Source

pub fn new() -> Self

Creates an empty rope containing a single empty line.

Source

pub fn root(&self) -> &RopeNode

Accesses the root node of the B-Tree.

Source

pub fn root_mut(&mut self) -> &mut RopeNode

Accesses the root node of the B-Tree mutably.

Source

pub fn height(&self) -> usize

Returns the tree height of the balanced B-Tree rope.

Source

pub fn from_str(text: &str) -> Self

Constructs a TextRope by splitting an input string along linebreaks (\n or \r\n).

Source

pub fn line_count(&self) -> usize

Total number of lines in the buffer.

Source

pub fn total_char_count(&self) -> usize

Total number of characters in the buffer.

Source

pub fn total_byte_count(&self) -> usize

Total number of bytes in the buffer.

Source

pub fn insert_line(&mut self, line_idx: usize, text: String)

Inserts a new line into the B-Tree at index line_idx, maintaining B-Tree balance.

Source

pub fn delete_line(&mut self, line_idx: usize) -> Option<String>

Deletes the line at index line_idx, collapsing internal nodes if necessary.

Source

pub fn line(&self, idx: usize) -> Option<&str>

Returns a reference to the line at the specified 0-based index.

Source

pub fn line_mut(&mut self, idx: usize) -> Option<&mut String>

Returns a mutable reference to the line at the specified 0-based index.

Source

pub fn line_len(&self, idx: usize) -> usize

Returns the character length of the line at the specified index.

Source

pub fn line_char_count(&self, idx: usize) -> usize

Returns the character count of the line at the specified index.

Source

pub fn line_byte_len(&self, idx: usize) -> usize

Returns the byte length of the line at the specified index.

Source

pub fn insert_char(&mut self, line: usize, col: usize, ch: char)

Inserts a character at the specified line and character column.

Source

pub fn insert_str(&mut self, line: usize, col: usize, text: &str)

Inserts a string at the specified line and character column, automatically handling multiline breaks.

Source

pub fn split_line(&mut self, line: usize, col: usize)

Splits a line into two lines at the given character column index.

Source

pub fn join_line_with_next(&mut self, line: usize)

Joins the specified line with the subsequent line.

Source

pub fn delete_backwards( &mut self, line: usize, col: usize, ) -> Option<(usize, usize)>

Deletes a character before the specified position (backspace).

Source

pub fn delete_range( &mut self, start_line: usize, start_col: usize, end_line: usize, end_col: usize, ) -> String

Deletes text within the given bounding character range and returns the deleted substring.

Source

pub fn slice_lines(&self, start: usize, count: usize) -> Vec<(usize, &str)>

Returns a slice of lines for virtual viewport rendering in logarithmic time.

Source

pub fn to_text(&self) -> String

Serializes entire rope back into a single newline-separated String.

Trait Implementations§

Source§

impl Clone for TextRope

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TextRope

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for TextRope

Source§

fn default() -> Self

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

impl Eq for TextRope

Source§

impl PartialEq for TextRope

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TextRope

Auto Trait Implementations§

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

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.