BufReadExt

Trait BufReadExt 

Source
pub trait BufReadExt<Char = char>
where Char: CharExt + Into<char> + Copy, for<'a> &'a [Char]: CharSet<Item = Char>, for<'a> &'a str: StrExt<'a, Char>,
{
Show 15 methods // Required methods fn get_cur_line(&self) -> &str; unsafe fn skip(&mut self, n: usize); fn read_buf(&mut self) -> Result<bool, StreamError>; fn fill_buf(&mut self) -> Result<(), StreamError>; // Provided methods fn is_eol(&self) -> bool { ... } fn get_line(&mut self) -> Result<&str, StreamError> { ... } fn get_in_cur_line(&mut self) -> Result<Option<char>, StreamError> { ... } fn peek_in_cur_line(&mut self) -> Option<char> { ... } fn fill_buf_if_eol(&mut self) -> Result<bool, StreamError> { ... } fn try_get(&mut self) -> Result<char, StreamError> { ... } fn try_peek(&mut self) -> Result<char, StreamError> { ... } fn try_skip_any(&mut self) -> Result<(), StreamError> { ... } fn try_skip_eol(&mut self) -> Result<Option<bool>, StreamError> { ... } fn try_get_line(&mut self) -> Result<&str, StreamError> { ... } fn try_get_line_some(&mut self) -> Result<&str, StreamError> { ... }
}
Expand description

Extension trait for BufRead.

It provides a way to read:

Currently, available Char types are char and FixedUtf8Char.

§Note

Current line means the unconsumed part of the line buffer.

Required Methods§

Source

fn get_cur_line(&self) -> &str

Get the current line whatever state it is.

Source

unsafe fn skip(&mut self, n: usize)

Skip n bytes.

§Safety

The caller must ensure that n is a valid UTF-8 character boundary.

Source

fn read_buf(&mut self) -> Result<bool, StreamError>

Try to fill the buffer with a new line, ignoring the current line.

Returns true if a new line is read.

Source

fn fill_buf(&mut self) -> Result<(), StreamError>

Fill the buffer with a new line, ignoring the current line.

  • Returns Ok(()) if a new line is read.
  • Returns Err if the buffer cannot be filled with a new line.

Provided Methods§

Source

fn is_eol(&self) -> bool

Check whether is at the end of the line.

Source

fn get_line(&mut self) -> Result<&str, StreamError>

Get the current line. Read a new line if current line is empty.

Source

fn get_in_cur_line(&mut self) -> Result<Option<char>, StreamError>

Get the next character in current line, if any.

Source

fn peek_in_cur_line(&mut self) -> Option<char>

Peek the next character in current line, if any.

Source

fn fill_buf_if_eol(&mut self) -> Result<bool, StreamError>

Fill the buffer with a new line if the current line is empty.

  • Returns Ok(true) if a new line is read.
  • Returns Ok(false) if the current line is not empty.
  • Returns Err if the buffer cannot be filled with a new line.
Source

fn try_get(&mut self) -> Result<char, StreamError>

Get a single character.

Source

fn try_peek(&mut self) -> Result<char, StreamError>

Peek a single character. Read a new line if current line is empty.

Source

fn try_skip_any(&mut self) -> Result<(), StreamError>

Skip a single character.

Source

fn try_skip_eol(&mut self) -> Result<Option<bool>, StreamError>

Go to the next line if the remaining part are end of line characters.

  • Returns Ok(Some(true)) if a new line is read.
  • Returns Ok(Some(false)) if the current line is empty, but can’t read a new line.
  • Returns Ok(None) if current line is not empty.
Source

fn try_get_line(&mut self) -> Result<&str, StreamError>

Get a single line. The trailing newline will be consumed and trimmed. but no other white spaces will be trimmed.

It can return an empty string.

Source

fn try_get_line_some(&mut self) -> Result<&str, StreamError>

Get a single not-empty line. The trailing newline will be consumed and trimmed.

Repeatedly read a new line if current line is empty.

Implementations on Foreign Types§

Source§

impl<S: ?Sized + BufReadExt<Char>, Char> BufReadExt<Char> for &mut S
where Char: CharExt + Into<char> + Copy, for<'a> &'a [Char]: CharSet<Item = Char>, for<'a> &'a str: StrExt<'a, Char>,

Source§

fn get_cur_line(&self) -> &str

Source§

unsafe fn skip(&mut self, n: usize)

Source§

fn read_buf(&mut self) -> Result<bool, StreamError>

Source§

fn fill_buf(&mut self) -> Result<(), StreamError>

Implementors§