InputStream

Struct InputStream 

Source
pub struct InputStream<B> { /* private fields */ }
Expand description

C++-like Stream.

This struct provides a way to read from a buffer that implements BufRead.

It implements BufReadExt for reading characters, strings, and lines.

Implementations§

Source§

impl<B: BufRead> InputStream<B>

Source

pub const fn new(buffer: B) -> Self

Create an input stream from a buffer that implements BufRead.

Trait Implementations§

Source§

impl<B: BufRead> BufReadExt for InputStream<B>

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. Read more
Source§

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

Try to fill the buffer with a new line, ignoring the current line. Read more
Source§

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

Fill the buffer with a new line, ignoring the current line. Read more
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. Read more
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. Read more
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. Read more
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. Read more

Auto Trait Implementations§

§

impl<B> Freeze for InputStream<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for InputStream<B>
where B: RefUnwindSafe,

§

impl<B> Send for InputStream<B>
where B: Send,

§

impl<B> Sync for InputStream<B>
where B: Sync,

§

impl<B> Unpin for InputStream<B>
where B: Unpin,

§

impl<B> UnwindSafe for InputStream<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

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

Source§

fn try_get_non_skipped<S>(&mut self, skip: S) -> Result<char, StreamError>
where S: CharSet<Item = Char>,

Get a single non-skipped character.
Source§

fn try_skip_all<S>(&mut self, skip: S) -> Result<usize, StreamError>
where S: CharSet<Item = Char>,

Skip all skipped characters until a non-skipped character is found or end of file.
Source§

fn try_get_until_in_line<F>(&mut self, pattern: F) -> Result<&str, StreamError>
where F: CharSet<Item = Char>,

Read until a character in pattern is found or end of line.
Source§

fn try_get_while_in_line<F>( &mut self, pattern: F, ) -> Result<&str, PatternError<StreamError>>
where F: Pattern<Item = Char>,

Read while matching the pattern.
Source§

fn try_get_string_some<S, A>( &mut self, skip: S, accept: A, ) -> Result<&str, PatternError<StreamError>>
where S: CharSet<Item = Char>, A: Pattern<Item = Char>,

Get a single skipped-separated string. If current line is empty or all skipped, it will read a new line.
Source§

fn try_get_line_trimmed<S>(&mut self, skip: S) -> Result<&str, StreamError>
where S: CharSet<Item = Char>,

Get a single line. The trailing white spaces will be consumed and trimmed. Read more
Source§

fn try_get_line_some_trimmed<S>(&mut self, skip: S) -> Result<&str, StreamError>
where S: CharSet<Item = Char>,

Get a single not-empty line. Both leading and trailing white spaces will be consumed and trimmed. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ReadInto<U> for T
where T: BufReadExt, U: ReadFrom,

Source§

type Error = ReadError<<U as ReadFrom>::ParseError>

Errors that come from ReadOneFrom. Read more
Source§

fn try_read(&mut self) -> Result<U, <T as ReadInto<U>>::Error>

Read from self and parse into Self.
Source§

fn try_read_n(&mut self, n: usize) -> Result<Vec<U>, <T as ReadInto<U>>::Error>

Read n elements from self, parse into Self and aggregate them into a single Vec.
Source§

fn try_read_m_n( &mut self, m: usize, n: usize, ) -> Result<Vec<Vec<U>>, <T as ReadInto<U>>::Error>

Read m * n elements from self, parse into Self and aggregate them into a single Mat.
Source§

fn read(&mut self) -> T

Unwrap the result of ReadInto::try_read.
Source§

fn read_n(&mut self, n: usize) -> Vec<T>

Unwrap the result of ReadInto::try_read_n.
Source§

fn read_m_n(&mut self, m: usize, n: usize) -> Mat<T>

Unwrap the result of ReadInto::try_read_m_n.
Source§

impl<T, U> ReadOneInto<T> for U
where T: ReadOneFrom, U: BufReadExt,

Source§

type Error = ReadError<<T as ReadOneFrom>::ParseError>

Errors that come from ReadOneFrom. Read more
Source§

fn try_read_one(&mut self) -> Result<T, <U as ReadOneInto<T>>::Error>

Read one from self and parse into T.
Source§

fn try_read_in_char(&mut self) -> Result<T, <U as ReadOneInto<T>>::Error>

Read an element in a single non-whitespace character from self, parse into T.
Source§

fn try_read_in_line_trimmed( &mut self, ) -> Result<T, <U as ReadOneInto<T>>::Error>

Read an element in the remained line from self, parse into T.
Source§

fn try_read_in_line_some_trimmed( &mut self, ) -> Result<T, <U as ReadOneInto<T>>::Error>

Read an element in a single trimmed line that is not empty from self, parse into T.
Source§

fn try_read_all(&mut self) -> Result<Vec<T>, <U as ReadOneInto<T>>::Error>

Read all remaining elements from stream.
Source§

fn try_read_any_in_line( &mut self, ) -> Result<Vec<T>, <U as ReadOneInto<T>>::Error>

Read all elements in current line from self.
Source§

fn try_read_some_in_line( &mut self, ) -> Result<Vec<T>, <U as ReadOneInto<T>>::Error>

Read all elements in a non-empty line from self.
Source§

fn read_one(&mut self) -> T

Unwrap the result of ReadOneInto::try_read_one.
Source§

fn read_in_char(&mut self) -> T

Unwrap the result of ReadOneInto::try_read_in_char.
Source§

fn read_in_line_trimmed(&mut self) -> T

Source§

fn read_in_line_some_trimmed(&mut self) -> T

Source§

fn read_all(&mut self) -> Vec<T>

Unwrap the result of ReadOneInto::try_read_all.
Source§

fn read_any_in_line(&mut self) -> Vec<T>

Unwrap the result of ReadOneInto::try_read_any_in_line.
Source§

fn read_some_in_line(&mut self) -> Vec<T>

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.