pub trait Reader {
    type Error: Error;

    // Required methods
    fn read_char(&mut self) -> Result<Option<char>, Self::Error>;
    fn try_read_string(
        &mut self,
        s: &str,
        case_sensitive: bool
    ) -> Result<bool, Self::Error>;
    fn len_of_char_in_current_encoding(&self, c: char) -> usize;
}
Expand description

An object that provides characters to the tokenizer.

Patches are welcome for providing an efficient implementation over async streams, iterators, files, etc, as long as any dependencies come behind featureflags.

Required Associated Types§

source

type Error: Error

The error returned by this reader.

Required Methods§

source

fn read_char(&mut self) -> Result<Option<char>, Self::Error>

Return a new character from the input stream.

The input stream does not have to be preprocessed in any way, it can contain standalone surrogates and have inconsistent newlines.

source

fn try_read_string( &mut self, s: &str, case_sensitive: bool ) -> Result<bool, Self::Error>

Attempt to read an entire string at once, either case-insensitively or not.

case_sensitive=false means that characters of the input stream should be compared while ignoring ASCII-casing.

It can be assumed that this function is never called with a string that contains \r or \n.

If the next characters equal to s, this function consumes the respective characters from the input stream and returns true. If not, it does nothing and returns false.

source

fn len_of_char_in_current_encoding(&self, c: char) -> usize

Returns the number of bytes that the given character takes up in the current character encoding.

Implementations on Foreign Types§

source§

impl<R: Reader + ?Sized> Reader for Box<R>

§

type Error = <R as Reader>::Error

source§

fn read_char(&mut self) -> Result<Option<char>, Self::Error>

source§

fn try_read_string( &mut self, s: &str, case_sensitive: bool ) -> Result<bool, Self::Error>

source§

fn len_of_char_in_current_encoding(&self, c: char) -> usize

Implementors§