Skip to main content

TextBuffer

Struct TextBuffer 

Source
pub struct TextBuffer { /* private fields */ }
Expand description

A text buffer backed by a ropey::Rope.

Every mutating operation increments an internal revision counter so that downstream systems (layout caches, syntax highlights, diagnostics, etc.) can cheaply detect stale data.

Implementations§

Source§

impl TextBuffer

Source

pub fn new() -> Self

Create an empty buffer.

Source

pub fn from_str(text: &str) -> Self

Create a buffer pre-populated with text.

Source§

impl TextBuffer

Source

pub fn text(&self) -> &Rope

Return a reference to the underlying rope.

Source

pub fn len_bytes(&self) -> usize

Total length in bytes (UTF-8).

Source

pub fn len_chars(&self) -> usize

Total length in Unicode characters (grapheme-unaware; counts chars).

Source

pub fn len_lines(&self) -> usize

Number of lines. A trailing \n implies an additional empty final line, matching the convention used by most editors.

Source

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

Return the contents of line_idx (0-based) as a ropey::RopeSlice, including the line terminator if present.

§Panics

Panics if line_idx >= self.len_lines().

Source

pub fn slice(&self, byte_range: Range<usize>) -> RopeSlice<'_>

Return an arbitrary byte-offset range as a RopeSlice.

Both bounds are byte offsets and must lie on char boundaries.

§Panics

Panics if the range is out of bounds or not on char boundaries.

Source

pub fn revision(&self) -> u64

Monotonically increasing revision counter. Incremented on every mutation (insert, delete, replace).

Source

pub fn is_empty(&self) -> bool

true when the buffer contains no characters.

Source§

impl TextBuffer

Source

pub fn insert(&mut self, byte_offset: usize, text: &str)

Insert text at the given byte offset.

§Panics

Panics if byte_offset is out of bounds or not on a char boundary.

Source

pub fn delete(&mut self, byte_range: Range<usize>)

Delete the byte range start..end.

§Panics

Panics if the range is out of bounds or not on char boundaries.

Source

pub fn replace(&mut self, byte_range: Range<usize>, text: &str)

Replace the byte range start..end with text.

Equivalent to a delete followed by an insert but only bumps the revision once.

Trait Implementations§

Source§

impl Clone for TextBuffer

Source§

fn clone(&self) -> TextBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBuffer

Source§

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

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

impl Default for TextBuffer

Source§

fn default() -> Self

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

impl Display for TextBuffer

Source§

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

Formats the value using the given formatter. Read more

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

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.