Skip to main content

RopeBuffer

Struct RopeBuffer 

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

A rope-based line buffer for efficient large document storage.

Instead of storing each line as a separate allocation, lines are grouped into chunks of CHUNK_SIZE lines. This reduces:

  • Memory fragmentation
  • Allocation overhead
  • Cache misses during iteration

Implementations§

Source§

impl RopeBuffer

Source

pub fn new(max_lines: usize) -> Self

Create a new rope buffer with the given maximum capacity.

§Arguments
  • max_lines - Maximum lines to retain. 0 means unlimited.
Source

pub fn unbounded() -> Self

Create an unbounded rope buffer.

Source

pub const fn len(&self) -> usize

Get the total number of lines.

Source

pub const fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub const fn chunk_count(&self) -> usize

Get the number of chunks.

Source

pub fn get_line(&self, index: usize) -> Option<&ChunkedLine>

Get a line by global index.

Source

pub fn get_line_mut(&mut self, index: usize) -> Option<&mut ChunkedLine>

Get a mutable reference to a line by global index.

Source

pub fn current_line(&self) -> Option<&ChunkedLine>

Get the current (last) line.

Source

pub fn current_line_mut(&mut self) -> Option<&mut ChunkedLine>

Get a mutable reference to the current (last) line.

Source

pub fn push_line(&mut self, line: ChunkedLine)

Push a new line to the buffer.

Source

pub fn newline(&mut self)

Add a new empty line.

Source

pub fn append(&mut self, cells: impl Iterator<Item = Cell>)

Append cells to the current line.

Source

pub fn clear(&mut self)

Clear all content.

Source

pub const fn scroll_offset(&self) -> usize

Get the current scroll offset.

Source

pub fn scroll_up(&mut self, lines: usize)

Scroll up by the given number of lines.

Source

pub const fn scroll_down(&mut self, lines: usize)

Scroll down by the given number of lines.

Source

pub const fn scroll_to_bottom(&mut self)

Scroll to the bottom (most recent content).

Source

pub fn visible_lines( &self, viewport_height: usize, ) -> impl Iterator<Item = (usize, &ChunkedLine)>

Iterate over lines in the visible range.

Returns an iterator over (line_index, &ChunkedLine) for lines that should be visible given the viewport height.

Source

pub fn memory_stats(&self) -> RopeMemoryStats

Get memory usage statistics.

Trait Implementations§

Source§

impl Debug for RopeBuffer

Source§

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

Formats the value using the given formatter. Read more

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