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
impl RopeBuffer
Sourcepub fn new(max_lines: usize) -> Self
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.
Sourcepub const fn chunk_count(&self) -> usize
pub const fn chunk_count(&self) -> usize
Get the number of chunks.
Sourcepub fn get_line(&self, index: usize) -> Option<&ChunkedLine>
pub fn get_line(&self, index: usize) -> Option<&ChunkedLine>
Get a line by global index.
Sourcepub fn get_line_mut(&mut self, index: usize) -> Option<&mut ChunkedLine>
pub fn get_line_mut(&mut self, index: usize) -> Option<&mut ChunkedLine>
Get a mutable reference to a line by global index.
Sourcepub fn current_line(&self) -> Option<&ChunkedLine>
pub fn current_line(&self) -> Option<&ChunkedLine>
Get the current (last) line.
Sourcepub fn current_line_mut(&mut self) -> Option<&mut ChunkedLine>
pub fn current_line_mut(&mut self) -> Option<&mut ChunkedLine>
Get a mutable reference to the current (last) line.
Sourcepub fn push_line(&mut self, line: ChunkedLine)
pub fn push_line(&mut self, line: ChunkedLine)
Push a new line to the buffer.
Sourcepub const fn scroll_offset(&self) -> usize
pub const fn scroll_offset(&self) -> usize
Get the current scroll offset.
Sourcepub const fn scroll_down(&mut self, lines: usize)
pub const fn scroll_down(&mut self, lines: usize)
Scroll down by the given number of lines.
Sourcepub const fn scroll_to_bottom(&mut self)
pub const fn scroll_to_bottom(&mut self)
Scroll to the bottom (most recent content).
Sourcepub fn visible_lines(
&self,
viewport_height: usize,
) -> impl Iterator<Item = (usize, &ChunkedLine)>
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.
Sourcepub fn memory_stats(&self) -> RopeMemoryStats
pub fn memory_stats(&self) -> RopeMemoryStats
Get memory usage statistics.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RopeBuffer
impl RefUnwindSafe for RopeBuffer
impl Send for RopeBuffer
impl Sync for RopeBuffer
impl Unpin for RopeBuffer
impl UnwindSafe for RopeBuffer
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
Mutably borrows from an owned value. Read more