Struct Buffer

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

A buffer for text in the line editor.

It keeps track of each action performed on it for use with undo/redo.

Implementations§

Source§

impl Buffer

Source

pub fn new() -> Self

Source

pub fn clear_actions(&mut self)

Source

pub fn start_undo_group(&mut self)

Source

pub fn end_undo_group(&mut self)

Source

pub fn undo(&mut self) -> bool

Source

pub fn redo(&mut self) -> bool

Source

pub fn revert(&mut self) -> bool

Source

pub fn last_arg(&self) -> Option<&[char]>

Source

pub fn num_chars(&self) -> usize

Source

pub fn num_bytes(&self) -> usize

Source

pub fn char_before(&self, cursor: usize) -> Option<char>

Source

pub fn char_after(&self, cursor: usize) -> Option<char>

Source

pub fn remove(&mut self, start: usize, end: usize) -> usize

Returns the number of characters removed.

Source

pub fn insert(&mut self, start: usize, text: &[char])

Source

pub fn insert_from_buffer(&mut self, other: &Buffer)

Source

pub fn copy_buffer(&mut self, other: &Buffer)

Source

pub fn range(&self, start: usize, end: usize) -> String

Source

pub fn range_chars(&self, start: usize, end: usize) -> Vec<char>

Source

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

Source

pub fn range_width(&self, start: usize, end: usize) -> Vec<usize>

Source

pub fn lines(&self) -> Vec<String>

Source

pub fn chars(&self) -> Iter<'_, char>

Source

pub fn truncate(&mut self, num: usize)

Source

pub fn print<W>(&self, out: &mut W) -> Result<()>
where W: Write,

Source

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

Source

pub fn print_rest<W>(&self, out: &mut W, after: usize) -> Result<usize>
where W: Write,

Takes other buffer, measures its length and prints this buffer from the point where the other stopped. Used to implement autosuggestions.

Source

pub fn starts_with(&self, other: &Buffer) -> bool

Check if the other buffer starts with the same content as this one. Used to implement autosuggestions.

Source

pub fn contains(&self, pattern: &Buffer) -> bool

Check if the buffer contains pattern. Used to implement history search.

Source

pub fn is_empty(&self) -> bool

Return true if the buffer is empty.

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

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 Buffer

Source§

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

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

impl Default for Buffer

Source§

fn default() -> Self

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

impl Display for Buffer

Source§

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

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

impl<'a> From<&'a str> for Buffer

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl From<Buffer> for String

Source§

fn from(buf: Buffer) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Buffer

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<char> for Buffer

Source§

fn from_iter<T: IntoIterator<Item = char>>(t: T) -> Self

Creates a value from an iterator. Read more
Source§

impl PartialEq for Buffer

Source§

fn eq(&self, other: &Self) -> 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 Buffer

Auto Trait Implementations§

§

impl Freeze for Buffer

§

impl RefUnwindSafe for Buffer

§

impl Send for Buffer

§

impl Sync for Buffer

§

impl Unpin for Buffer

§

impl UnwindSafe for Buffer

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.