pub trait TextBuffer {
    // Required methods
    fn is_mutable(&self) -> bool;
    fn as_str(&self) -> &str;
    fn insert_text(&mut self, text: &str, char_index: usize) -> usize;
    fn delete_char_range(&mut self, char_range: Range<usize>);

    // Provided methods
    fn char_range(&self, char_range: Range<usize>) -> &str { ... }
    fn byte_index_from_char_index(&self, char_index: usize) -> usize { ... }
    fn clear(&mut self) { ... }
    fn replace_with(&mut self, text: &str) { ... }
    fn take(&mut self) -> String { ... }
}
Expand description

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

Most likely you will use a String which implements TextBuffer.

Required Methods§

source

fn is_mutable(&self) -> bool

Can this text be edited?

source

fn as_str(&self) -> &str

Returns this buffer as a str.

source

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

Inserts text text into this buffer at character index char_index.

Notes

char_index is a character index, not a byte index.

Return

Returns how many characters were successfully inserted

source

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

Deletes a range of text char_range from this buffer.

Notes

char_range is a character range, not a byte range.

Provided Methods§

source

fn char_range(&self, char_range: Range<usize>) -> &str

Reads the given character range.

source

fn byte_index_from_char_index(&self, char_index: usize) -> usize

source

fn clear(&mut self)

Clears all characters in this buffer

source

fn replace_with(&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.

Implementations on Foreign Types§

source§

impl TextBuffer for String

source§

fn is_mutable(&self) -> bool

source§

fn as_str(&self) -> &str

source§

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

source§

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

source§

fn clear(&mut self)

source§

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

source§

fn take(&mut self) -> String

source§

impl<'a> TextBuffer for &'a str

Immutable view of a &str!

source§

fn is_mutable(&self) -> bool

source§

fn as_str(&self) -> &str

source§

fn insert_text(&mut self, _text: &str, _ch_idx: usize) -> usize

source§

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

source§

impl<'a> TextBuffer for Cow<'a, str>

source§

fn is_mutable(&self) -> bool

source§

fn as_str(&self) -> &str

source§

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

source§

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

source§

fn clear(&mut self)

source§

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

source§

fn take(&mut self) -> String

Implementors§