Struct LineBuffer

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

Abstraction over a string to handle manipulation operations at char boundaries.

This exists because Rust strings are indexed by bytes and manipulating string bytes is complicated.

TODO(zenria): The current implementation of the buffer is using String::chars. Should be converted to using graphemes instead.

Implementations§

Source§

impl LineBuffer

Source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty LineBuffer with an allocated capacity.

Source

pub fn len(&self) -> usize

Returns the logical LineBuffer length (in UTF-8 code point count and not in bytes).

Source

pub fn chars(&self) -> Chars<'_>

Gets and iterator over buffer chars.

Source

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

Returns the end of the string starting at start_pos, or an empty string if start_pos is after the string’s end.

Source

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

Returns the characters from the start of the string to end_pos, excluding end_pos.

Calling this with end_pos set to 0 will return an empty string, and a 1-char string if end_pos is 1 (if the string contains at least 1 character).

Source

pub fn range(&self, start_pos: usize, end_pos: usize) -> String

Extracts a range of characters from this buffer.

Source

pub fn is_empty(&self) -> bool

Checks if this buffer is empty or not.

Source

pub fn as_bytes(&self) -> &[u8]

Gets a view on the underlying bytes held by this buffer.

Warning: direct bytes manipulation may lead to undefined behavior.

Source

pub fn remove(&mut self, pos: usize)

Removes a character from this buffer.

If the given position if greater than the length of the buffer, this function does nothing.

Source

pub fn insert(&mut self, pos: usize, ch: char)

Inserts a char at the given position.

If the position is greater than the buffer length, the character will be appended at the end ot it.

Source

pub fn into_inner(self) -> String

Returns the underlying string.

Source

pub fn insert_str(&mut self, pos: usize, s: &str)

Inserts the given string s into the buffer at pos.

If pos is greater than the length of the buffer, s will be appended at the end of it.

Source

pub fn push_str(&mut self, s: &LineBuffer)

Appends the given string s to the buffer.

Source

pub fn split_off(&mut self, at: usize) -> LineBuffer

Splits the buffer in two parts at the position at.

Returns the remaining part of the buffer (same behavior as String::split_off).

Trait Implementations§

Source§

impl Debug for LineBuffer

Source§

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

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

impl Default for LineBuffer

Source§

fn default() -> LineBuffer

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

impl Display for LineBuffer

Source§

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

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

impl From<&String> for LineBuffer

Source§

fn from(s: &String) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for LineBuffer

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for LineBuffer

Source§

fn from(line: String) -> Self

Converts to this type from the input type.

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> 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> 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V