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:
- A single non-empty line (BufReadExt::try_get_line_some),
- Or just the remained line (BufReadExt::try_get_line).
- …
Currently, available Char types are char and FixedUtf8Char.
§Note
Current line means the unconsumed part of the line buffer.
Required Methods§
Sourcefn get_cur_line(&self) -> &str
fn get_cur_line(&self) -> &str
Get the current line whatever state it is.
Provided Methods§
Sourcefn get_line(&mut self) -> Result<&str, StreamError>
fn get_line(&mut self) -> Result<&str, StreamError>
Get the current line. Read a new line if current line is empty.
Sourcefn get_in_cur_line(&mut self) -> Result<Option<char>, StreamError>
fn get_in_cur_line(&mut self) -> Result<Option<char>, StreamError>
Get the next character in current line, if any.
Sourcefn peek_in_cur_line(&mut self) -> Option<char>
fn peek_in_cur_line(&mut self) -> Option<char>
Peek the next character in current line, if any.
Sourcefn fill_buf_if_eol(&mut self) -> Result<bool, StreamError>
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
Errif the buffer cannot be filled with a new line.
Sourcefn try_peek(&mut self) -> Result<char, StreamError>
fn try_peek(&mut self) -> Result<char, StreamError>
Peek a single character. Read a new line if current line is empty.
Sourcefn try_skip_any(&mut self) -> Result<(), StreamError>
fn try_skip_any(&mut self) -> Result<(), StreamError>
Skip a single character.
Sourcefn try_skip_eol(&mut self) -> Result<Option<bool>, StreamError>
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.
Sourcefn try_get_line(&mut self) -> Result<&str, StreamError>
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.
Sourcefn try_get_line_some(&mut self) -> Result<&str, StreamError>
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.