Skip to main content

BufReadCharsExt

Trait BufReadCharsExt 

Source
pub trait BufReadCharsExt: BufRead {
    // Provided methods
    fn chars(&mut self) -> Chars<'_, Self>  { ... }
    fn chars_raw(&mut self) -> CharsRaw<'_, Self>  { ... }
    fn read_char(&mut self) -> Result<Option<char>> { ... }
    fn read_char_raw(&mut self) -> Result<Option<char>, ReadCharError> { ... }
}
Expand description

Extends BufRead with methods for reading chars.

Provided Methods§

Source

fn chars(&mut self) -> Chars<'_, Self>

Returns an iterator over the chars of this reader.

In contrast to chars_raw, the error type is io::Error, and therefore more likely to be drop-in compatible, at the price of losing the UTF-8 context bytes in the error message.

The iterator returned from this function will yield instances of io::Result<char>.

Source

fn chars_raw(&mut self) -> CharsRaw<'_, Self>

Returns an iterator over the chars of this reader.

The iterator returned from this function will yield instances of Result<char, ReadCharError>.

Source

fn read_char(&mut self) -> Result<Option<char>>

Reads a char from the underlying reader.

In contrast to read_char_raw, the error type is io::Error, and therefore more likely to be drop-in compatible, at the price of losing the UTF-8 context bytes in the error message.

Returns

  • Ok(Some(char)) if a char has successfully read,
  • Ok(None) if the stream has reached EOF before any byte was read,
  • Err(err) if an I/O error occurred, or read byte sequence was not recognised as a valid UTF-8.

If this function encounters an error of the kind io::ErrorKind::Interrupted then the error is ignored and the operation will continue.

Source

fn read_char_raw(&mut self) -> Result<Option<char>, ReadCharError>

Reads a char from the underlying reader.

Returns

  • Ok(Some(char)) if a char has successfully read,
  • Ok(None) if the stream has reached EOF before any byte was read,
  • Err(err) if an I/O error occurred, or read byte sequence was not recognised as a valid UTF-8.

If this function encounters an error of the kind io::ErrorKind::Interrupted then the error is ignored and the operation will continue.

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.

Implementors§