pub struct Buffer { /* private fields */ }
Expand description
A Gap buffer. This represents the text of a buffer, and allows for efficient insertion and deletion of text.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn with_gap(gap: usize) -> Self
pub fn with_gap(gap: usize) -> Self
Create a new empty text buffer with the specified gap size.
Sourcepub fn insert_char(&mut self, chr: char)
pub fn insert_char(&mut self, chr: char)
Insert a character into the buffer at the cursor.
Sourcepub fn delete_backwards(&mut self, size: usize)
pub fn delete_backwards(&mut self, size: usize)
Delete backwards from the cursor size
characters.
Sourcepub fn delete_forwards(&mut self, size: usize)
pub fn delete_forwards(&mut self, size: usize)
Delete forwards from the cursor size
characters.
Sourcepub fn delete_range(&mut self, beg: usize, end: usize)
pub fn delete_range(&mut self, beg: usize, end: usize)
Delete all text between the two character positions.
Sourcepub fn move_gap_out_of(&mut self, range: impl RangeBounds<usize>)
pub fn move_gap_out_of(&mut self, range: impl RangeBounds<usize>)
Move the gap out of range
. This is useful when you need to access the
data in a contiguous manner.
Sourcepub fn set_cursor(&mut self, pos: usize)
pub fn set_cursor(&mut self, pos: usize)
Set the cursor to the pos
character.
Sourcepub fn char_to_byte(&self, pos: usize) -> usize
pub fn char_to_byte(&self, pos: usize) -> usize
Covert the character position to a byte position.
Sourcepub fn byte_to_char(&self, pos: usize) -> usize
pub fn byte_to_char(&self, pos: usize) -> usize
Convert the byte position to a character position.
Sourcepub fn slice(&self, bounds: impl RangeBounds<usize>) -> (&str, &str)
pub fn slice(&self, bounds: impl RangeBounds<usize>) -> (&str, &str)
Get a slice from the buffer with the given character bounds. If the slice is split across
the gap, the two halves are returned separately. If a contiguous slice is needed, call
](crate::Buffer::slice_[
move_gap_out_of`](crate::Buffer::move_gap_out_of) first.
Trait Implementations§
Source§impl GetSize for Buffer
impl GetSize for Buffer
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)
fn get_heap_size_with_tracker<TRACKER: GetSizeTracker>( &self, tracker: TRACKER, ) -> (usize, TRACKER)
tracker
. Read more§fn get_stack_size() -> usize
fn get_stack_size() -> usize
§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker
. Read more