Skip to main content

TextBuffer

Struct TextBuffer 

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

A mutable text buffer backed by a String.

Implementations§

Source§

impl TextBuffer

Source

pub fn new() -> Self

Source

pub fn with_capacity(cap: usize) -> Self

Source

pub fn append(&mut self, s: &str)

Append a string slice.

Source

pub fn append_line(&mut self, s: &str)

Append a line (adds newline at end).

Source

pub fn char_count(&self) -> usize

Total character count.

Source

pub fn byte_len(&self) -> usize

Total byte count.

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_str(&self) -> &str

Returns the buffer as a string slice.

Source

pub fn line_count(&self) -> usize

Returns the number of lines.

Source

pub fn line(&self, n: usize) -> Option<&str>

Returns the nth line (0-indexed).

Source

pub fn lines_vec(&self) -> Vec<&str>

Returns all lines as a vector.

Source

pub fn find(&self, needle: &str) -> Option<usize>

Search for a substring; returns the byte offset of the first match.

Source

pub fn count_occurrences(&self, needle: &str) -> usize

Count occurrences of a substring.

Source

pub fn replace_all(&mut self, from: &str, to: &str)

Replace all occurrences of from with to.

Source

pub fn clear(&mut self)

Clear the buffer.

Source

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

Truncate to the first n bytes (must be on a char boundary).

Source

pub fn append_count(&self) -> u64

Trait Implementations§

Source§

impl Default for TextBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> Same for T

Source§

type Output = T

Should always be Self
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.