Skip to main content

TextBuffer

Trait TextBuffer 

Source
pub trait TextBuffer {
    // Required methods
    fn create_buffer(init_size: usize) -> Self
       where Self: Sized;
    fn insert(&mut self, pos: usize, char: char);
    fn delete(&mut self, start: usize, len: usize);
    fn read(
        &self,
        start: usize,
        end: usize,
    ) -> impl DoubleEndedIterator<Item = &char>;
    fn len(&self) -> usize;
}
Expand description

A trait for creating and manipulating text buffers.

Current implementations: [GapBuffer] Planned implementations: Rope, PieceTable

Required Methods§

Source

fn create_buffer(init_size: usize) -> Self
where Self: Sized,

Creates a new text buffer.

init_size parameter determines the initial size of the buffer

Source

fn insert(&mut self, pos: usize, char: char)

Inserts into a text buffer.

Inserts char at pos (0-indexed). Reallocates buffer if filled.

§Panics

Panics if pos is out of bounds.

Source

fn delete(&mut self, start: usize, len: usize)

Deletes from a text buffer.

Deletes len characters starting at start (0-indexed)

§Panics

To be filled in later.

Source

fn read( &self, start: usize, end: usize, ) -> impl DoubleEndedIterator<Item = &char>

Reads from a text buffer.

Returns a DoubleEndedIterator for bidirectional traversal. Reads characters from start (0-indexed) to end (exclusive).

§Panics

Panics if start is out of bounds. Panics if end is out of bounds. Panics if start is greater than end.

Source

fn len(&self) -> usize

Returns the current length of a text buffer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§