Trait Read

Source
pub trait Read {
    // Required methods
    fn position(&self) -> Position;
    fn peek(&mut self) -> Result<Option<u8>, ReadError>;
    fn next(&mut self) -> Result<Option<u8>, ReadError>;

    // Provided methods
    fn discard(&mut self) { ... }
    fn next4(&mut self) -> Result<[u8; 4], ReadError> { ... }
    fn next5(&mut self) -> Result<[u8; 5], ReadError> { ... }
    fn skip_whitespace(&mut self) -> Result<(), ReadError> { ... }
    fn next_number(&mut self) -> Result<(), ReadError> { ... }
    fn next_likely_string(&mut self, buf: &mut Vec<u8>) -> Result<(), ReadError> { ... }
}
Expand description

A trait for reading characters from a source.

§Performance

All provided methods might not be the most efficient way to read characters as it might return the ReadError, which basically an std::io::Error. However, reading characters from in memory source should raise std::io::Error, so you could implement your own Read trait and its provided methods for better performance, such as SliceRead.

Required Methods§

Source

fn position(&self) -> Position

Get the current position of the reader.

Source

fn peek(&mut self) -> Result<Option<u8>, ReadError>

Peek the next character without consuming it.

Source

fn next(&mut self) -> Result<Option<u8>, ReadError>

Get the next character and consume it.

Provided Methods§

Source

fn discard(&mut self)

Discard the next character.

§Panic

This method panics if the next character is None.

Source

fn next4(&mut self) -> Result<[u8; 4], ReadError>

Get the next 4 characters and consume them.

Source

fn next5(&mut self) -> Result<[u8; 5], ReadError>

Get the next 5 characters and consume them.

Source

fn skip_whitespace(&mut self) -> Result<(), ReadError>

Skip whitespace characters (' ', '\t', '\n', '\r').

Source

fn next_number(&mut self) -> Result<(), ReadError>

Parse a number and allow arbitrary precision.

Source

fn next_likely_string(&mut self, buf: &mut Vec<u8>) -> Result<(), ReadError>

Parse a string, but not guaranteed to be correct UTF-8.

Implementors§

Source§

impl Read for StrRead<'_>

Source§

impl<'a> Read for SliceRead<'a>

Source§

impl<R: Read> Read for IoRead<R>