pub struct GapBuffer { /* private fields */ }Expand description
An implementation of a gap buffer that tracks internal meta-data to help with accessing sub-regions of the text such as character ranges and lines.
Implementations§
source§impl GapBuffer
impl GapBuffer
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
The current length of “active” data in the buffer (i.e. not including the gap)
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether or not the visible buffer contents are empty or not. This can return true while there is “deleted” data in the gap.
pub fn iter_lines(&self) -> impl Iterator<Item = Slice<'_>>
pub fn len_lines(&self) -> usize
pub fn len_chars(&self) -> usize
pub fn clear(&mut self)
pub fn char(&self, char_idx: usize) -> char
pub fn get_char(&self, char_idx: usize) -> Option<char>
pub fn line(&self, line_idx: usize) -> Slice<'_>
pub fn line_len_chars(&self, line_idx: usize) -> usize
sourcepub fn slice(&self, char_from: usize, char_to: usize) -> Slice<'_>
pub fn slice(&self, char_from: usize, char_to: usize) -> Slice<'_>
An exclusive range of characters from the buffer
pub fn byte_to_char(&self, byte_idx: usize) -> usize
pub fn char_to_line(&self, char_idx: usize) -> usize
pub fn try_char_to_line(&self, char_idx: usize) -> Option<usize>
pub fn line_to_char(&self, line_idx: usize) -> usize
pub fn try_line_to_char(&self, line_idx: usize) -> Option<usize>
sourcepub fn insert_char(&mut self, char_idx: usize, ch: char)
pub fn insert_char(&mut self, char_idx: usize, ch: char)
Insert a single character at the specifified byte index.
This is O(1) if idx is at the current gap start and the gap is large enough to accomodate the new text, otherwise data will need to be copied in order to relocate the gap.
sourcepub fn insert_str(&mut self, char_idx: usize, s: &str)
pub fn insert_str(&mut self, char_idx: usize, s: &str)
Insert a string at the specifified byte index.
This is O(1) if idx is at the current gap start and the gap is large enough to accomodate the new text, otherwise data will need to be copied in order to relocate the gap.
sourcepub fn remove_char(&mut self, char_idx: usize)
pub fn remove_char(&mut self, char_idx: usize)
Remove the requested character index from the visible region of the buffer
sourcepub fn remove_range(&mut self, char_from: usize, char_to: usize)
pub fn remove_range(&mut self, char_from: usize, char_to: usize)
Remove the requested range (from..to) from the visible region of the buffer
Trait Implementations§
source§impl Address for GapBuffer
impl Address for GapBuffer
source§fn current_dot(&self) -> Dot
fn current_dot(&self) -> Dot
fn len_chars(&self) -> usize
fn line_to_char(&self, line_idx: usize) -> Option<usize>
fn char_to_line(&self, char_idx: usize) -> Option<usize>
fn char_to_line_end(&self, char_idx: usize) -> Option<usize>
fn char_to_line_start(&self, char_idx: usize) -> Option<usize>
fn max_iter(&self) -> usize
fn map_addr(&self, a: &mut Addr) -> Dot
fn full_line(&self, line_idx: usize) -> Option<Dot>
fn map_simple_addr(&self, addr: &mut SimpleAddr, cur_dot: Dot) -> Option<Dot>
fn map_compound_addr( &self, from: &mut SimpleAddr, to: &mut SimpleAddr, ) -> Option<Dot>
source§impl IterBoundedChars for GapBuffer
impl IterBoundedChars for GapBuffer
impl Eq for GapBuffer
impl StructuralPartialEq for GapBuffer
Auto Trait Implementations§
impl Freeze for GapBuffer
impl RefUnwindSafe for GapBuffer
impl Send for GapBuffer
impl Sync for GapBuffer
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)