Struct 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<'_>>

Iterate over the lines of the buffer

Source

pub fn len_lines(&self) -> usize

The number of lines within the buffer

Source

pub fn len_chars(&self) -> usize

The number of characters in the buffer

Source

pub fn byte_line_endings(&self) -> Vec<usize>

Source

pub fn clear(&mut self)

Clear the contents of the buffer.

§Note

This does not actually zero out the data currently within the buffer or truncate the allocation in any way. It simply resets internal state so that it behaves like an empty initial buffer.

Source

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

The character at the specified character index.

§Panics

This method will panic if the given character index is out of bounds

Source

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

The character at the specified character index.

Source

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

The requested line as a Slice.

§Panics

This method will panic if the given line index is out of bounds

Source

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

The number of characters in the requested line.

§Panics

This method will panic if the given line index is out of bounds

Source

pub fn maximal_slice_from_offset(&self, byte_offset: usize) -> &[u8]

Primarily intended for supplying contiguous ranges of bytes to tree-sitter when parsing. Returns a byte slice from the underlying data buffer without entering the gap.

Source

pub fn slice_from_byte_offsets( &self, byte_from: usize, byte_to: usize, ) -> Slice<'_>

An exclusive range of characters from the buffer

Source

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

An exclusive range of characters from the buffer

Source

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

Convert a byte index to a character index

Source

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

Convert a character index to the index of the line containing it

§Panics

This method will panic if the given char index is out of bounds

Source

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

Convert a character index to the index of the line containing it

Source

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

Convert a line index to the character index of its first character

§Panics

This method will panic if the given char index is out of bounds

Source

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

Convert a line index to the character index of its first character

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.

§Panics

This method will panic if char_from < char_to

Source

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

Convert a character offset within the logical buffer to a byte offset within the logical buffer. This is used to account for multi-byte characters within the buffer and is treated as a String-like index but it does not account for the position of the gap.

Source

pub fn byte_to_raw_byte(&self, byte: usize) -> usize

Trait Implementations§

Source§

impl Clone for GapBuffer

Source§

fn clone(&self) -> GapBuffer

Returns a duplicate 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 insert(&mut self, idx: usize, s: &str)

Insert a string at the specified index
Source§

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

Remove all characters from (from..to)
Source§

fn submatch(&self, m: &Match, n: usize) -> Option<String>

Extract the content of a previous submatch so it can be used in templating
Source§

fn begin_edit_transaction(&mut self)

Mark the start of an edit transaction
Source§

fn end_edit_transaction(&mut self)

Mark the end of an edit transaction
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 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<'a> TextProvider<&'a [u8]> for &'a GapBuffer

Source§

type I = SliceIter<'a>

Source§

fn text(&mut self, node: Node<'_>) -> Self::I

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more