pub struct GapBuffer { /* private fields */ }Expand description
A gap buffer structure.
Useful for small and frequent insertions and deletions. O(1) insertions and deletions on average. O(n) gap repositioning on edit location change.
Example use case: Shell
Trait Implementations§
Source§impl TextBuffer for GapBuffer
impl TextBuffer for GapBuffer
Source§fn create_buffer(init_size: usize) -> Selfwhere
Self: Sized,
fn create_buffer(init_size: usize) -> Selfwhere
Self: Sized,
Creates a gap buffer according to gap size.
Start is at first insertable location. End is at first character after last insertable location.
Buffer is initialized to designated gap size.
Source§fn insert(&mut self, pos: usize, char: char)
fn insert(&mut self, pos: usize, char: char)
Inserts into a gap buffer.
- Moves gap
- Checks if gap is empty (if so, resize by doubling existing buffer length)
- Insert at
gap_startand increment gap_start by 1 (slot filled)
§Panics
Panics if pos is out of bounds.
Source§fn delete(&mut self, start: usize, len: usize)
fn delete(&mut self, start: usize, len: usize)
Deletes from a gap buffer.
- Moves gap
- Extends gap by
lenby adding togap_end
§Panics
Panics if gap_end + len is out of bounds.
Auto Trait Implementations§
impl Freeze for GapBuffer
impl RefUnwindSafe for GapBuffer
impl Send for GapBuffer
impl Sync for GapBuffer
impl Unpin for GapBuffer
impl UnsafeUnpin for GapBuffer
impl UnwindSafe for GapBuffer
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