Struct ad_editor::buffer::GapBuffer

source ·
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

source

pub fn len(&self) -> usize

The current length of “active” data in the buffer (i.e. not including the gap)

source

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.

source

pub fn bytes(&self) -> Vec<u8>

The raw content of the buffer

source

pub fn iter_lines(&self) -> impl Iterator<Item = Slice<'_>>

source

pub fn len_lines(&self) -> usize

source

pub fn len_chars(&self) -> usize

source

pub fn clear(&mut self)

source

pub fn char(&self, char_idx: usize) -> char

source

pub fn get_char(&self, char_idx: usize) -> Option<char>

source

pub fn line(&self, line_idx: usize) -> Slice<'_>

source

pub fn line_len_chars(&self, line_idx: usize) -> usize

source

pub fn slice(&self, char_from: usize, char_to: usize) -> Slice<'_>

An exclusive range of characters from the buffer

source

pub fn byte_to_char(&self, byte_idx: usize) -> usize

source

pub fn char_to_line(&self, char_idx: usize) -> usize

source

pub fn try_char_to_line(&self, char_idx: usize) -> Option<usize>

source

pub fn line_to_char(&self, line_idx: usize) -> usize

source

pub fn try_line_to_char(&self, line_idx: usize) -> Option<usize>

source

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.

source

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.

source

pub fn remove_char(&mut self, char_idx: usize)

Remove the requested character index from the visible region of the buffer

source

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

source§

fn current_dot(&self) -> Dot

This only really makes sense for use with a buffer but is supported so that don’t need to special case running programs against an in-editor buffer vs stdin or a file read from disk.
source§

fn len_chars(&self) -> usize

source§

fn line_to_char(&self, line_idx: usize) -> Option<usize>

source§

fn char_to_line(&self, char_idx: usize) -> Option<usize>

source§

fn char_to_line_end(&self, char_idx: usize) -> Option<usize>

source§

fn char_to_line_start(&self, char_idx: usize) -> Option<usize>

source§

fn max_iter(&self) -> usize

source§

fn map_addr(&self, a: &mut Addr) -> Dot

source§

fn full_line(&self, line_idx: usize) -> Option<Dot>

source§

fn map_simple_addr(&self, addr: &mut SimpleAddr, cur_dot: Dot) -> Option<Dot>

source§

fn map_compound_addr( &self, from: &mut SimpleAddr, to: &mut SimpleAddr, ) -> Option<Dot>

source§

impl Clone for GapBuffer

source§

fn clone(&self) -> GapBuffer

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for GapBuffer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for GapBuffer

source§

fn default() -> GapBuffer

Returns the “default value” for a type. Read more
source§

impl Display for GapBuffer

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Edit for GapBuffer

source§

fn contents(&self) -> String

source§

fn insert(&mut self, idx: usize, s: &str)

source§

fn remove(&mut self, from: usize, to: usize)

source§

fn begin_edit_transaction(&mut self)

source§

fn end_edit_transaction(&mut self)

source§

impl From<&str> for GapBuffer

source§

fn from(s: &str) -> Self

Converts to this type from the input type.
source§

impl From<String> for GapBuffer

source§

fn from(s: String) -> Self

Converts to this type from the input type.
source§

impl IterBoundedChars for GapBuffer

source§

fn iter_between(&self, from: usize, to: usize) -> CharIter<'_>

Iterate forward: from -> to Read more
source§

fn rev_iter_between(&self, from: usize, to: usize) -> CharIter<'_>

Iterate backward: from -> to Read more
source§

impl PartialEq for GapBuffer

source§

fn eq(&self, other: &GapBuffer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for GapBuffer

source§

impl StructuralPartialEq for GapBuffer

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.