Trait Content

Source
pub trait Content: Sized {
    type Underlying: Clone + PartialEq;

    // Required methods
    fn get_range(&self, range: Range<usize>) -> &[Self::Underlying];
    fn decode_str(src: &str) -> Cow<'_, [Self::Underlying]>;
    fn encode_bytes(bytes: &[Self::Underlying]) -> Cow<'_, str>;
    fn get_char_column(&self, column: usize, offset: usize) -> usize;
}

Required Associated Types§

Required Methods§

Source

fn get_range(&self, range: Range<usize>) -> &[Self::Underlying]

Source

fn decode_str(src: &str) -> Cow<'_, [Self::Underlying]>

Used for string replacement. We need this for indentation and deindentation.

Source

fn encode_bytes(bytes: &[Self::Underlying]) -> Cow<'_, str>

Used for string replacement. We need this for transformation.

Source

fn get_char_column(&self, column: usize, offset: usize) -> usize

Get the character column at the given position

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 Content for String

Source§

fn get_char_column(&self, _col: usize, offset: usize) -> usize

This is an O(n) operation. We assume the col will not be a huge number in reality. This may be problematic for special files like compressed js

Source§

type Underlying = u8

Source§

fn get_range(&self, range: Range<usize>) -> &[Self::Underlying]

Source§

fn decode_str(src: &str) -> Cow<'_, [Self::Underlying]>

Source§

fn encode_bytes(bytes: &[Self::Underlying]) -> Cow<'_, str>

Implementors§