Skip to main content

TextBuffer

Trait TextBuffer 

Source
pub trait TextBuffer: AsRef<str> + Into<String> {
    // Required methods
    fn insert_text(&mut self, text: &str, ch_idx: usize) -> usize;
    fn delete_char_range(&mut self, ch_range: Range<usize>);

    // Provided methods
    fn as_str(&self) -> &str { ... }
    fn clear(&mut self) { ... }
    fn replace(&mut self, text: &str) { ... }
    fn take(&mut self) -> String { ... }
}
Expand description

Trait constraining what types TextEdit may use as an underlying buffer.

Most likely you will use a String which implements TextBuffer.

Required Methods§

Source

fn insert_text(&mut self, text: &str, ch_idx: usize) -> usize

Inserts text text into this buffer at character index ch_idx.

§Notes

ch_idx is a character index, not a byte index.

§Return

Returns how many characters were successfully inserted

Source

fn delete_char_range(&mut self, ch_range: Range<usize>)

Deletes a range of text ch_range from this buffer.

§Notes

ch_range is a character range, not a byte range.

Provided Methods§

Source

fn as_str(&self) -> &str

Returns this buffer as a str.

This is an utility method, as it simply relies on the AsRef<str> implementation.

Source

fn clear(&mut self)

Clears all characters in this buffer

Source

fn replace(&mut self, text: &str)

Replaces all contents of this string with text

Source

fn take(&mut self) -> String

Clears all characters in this buffer and returns a string of the contents.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TextBuffer for String

Source§

fn insert_text(&mut self, text: &str, ch_idx: usize) -> usize

Source§

fn delete_char_range(&mut self, ch_range: Range<usize>)

Source§

fn clear(&mut self)

Source§

fn replace(&mut self, text: &str)

Source§

fn take(&mut self) -> String

Implementors§