Skip to main content

TextBuffer

Trait TextBuffer 

Source
pub trait TextBuffer {
    type Pos: Clone + Ord;

    // Required methods
    fn start_pos(&self) -> Self::Pos;
    fn end_pos(&self) -> Self::Pos;
    fn clamp_pos(&self, pos: Self::Pos) -> Self::Pos;
    fn prev_boundary(&self, pos: Self::Pos) -> Self::Pos;
    fn next_boundary(&self, pos: Self::Pos) -> Self::Pos;
    fn text_between(&self, start: Self::Pos, end: Self::Pos) -> String;
    fn replace(
        &mut self,
        start: Self::Pos,
        end: Self::Pos,
        text: &str,
    ) -> TextEdit<Self::Pos>;
}
Expand description

文本缓冲区契约。

Pos 可以是字节偏移(String)或 { line, col }(行式文档)。 所有位置参数在算法内都先经 clamp_pos,实现方必须保证返回值落在合法边界上。

Required Associated Types§

Required Methods§

Source

fn start_pos(&self) -> Self::Pos

Source

fn end_pos(&self) -> Self::Pos

Source

fn clamp_pos(&self, pos: Self::Pos) -> Self::Pos

Source

fn prev_boundary(&self, pos: Self::Pos) -> Self::Pos

Source

fn next_boundary(&self, pos: Self::Pos) -> Self::Pos

Source

fn text_between(&self, start: Self::Pos, end: Self::Pos) -> String

Source

fn replace( &mut self, start: Self::Pos, end: Self::Pos, text: &str, ) -> TextEdit<Self::Pos>

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl TextBuffer for String

Source§

type Pos = usize

Source§

fn start_pos(&self) -> usize

Source§

fn end_pos(&self) -> usize

Source§

fn clamp_pos(&self, pos: usize) -> usize

Source§

fn prev_boundary(&self, pos: usize) -> usize

Source§

fn next_boundary(&self, pos: usize) -> usize

Source§

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

Source§

fn replace(&mut self, start: usize, end: usize, text: &str) -> TextEdit<usize>

Implementors§