[−][src]Struct char_reader::CharReader
A buffered reader able to read chars or lines without crashing when the stream doesn't finish and/or doesn't contain newlines.
It's also able to avoid storying whole lines if you're only interested in their beginning.
Bad UTF8 is reported as io::Error with kind InvalidData.
Implementations
impl<R: Read> CharReader<R>
[src]
pub fn new(src: R) -> Self
[src]
pub fn load_char(&mut self) -> Result<Option<(char, usize)>>
[src]
ensure there's at least one char in the buffer, and returns it with its size in bytes (or None if the underlying stream is finished).
You probably don't need this function but next_char.
pub fn next_char(&mut self) -> Result<Option<char>>
[src]
read and return the next char, or NONE in case of EOF
pub fn peek_char(&mut self) -> Result<Option<char>>
[src]
return the next char, but doesn't advance the cursor
pub fn read_line(
&mut self,
line: &mut String,
drop_after: usize,
fail_after: usize
) -> Result<bool>
[src]
&mut self,
line: &mut String,
drop_after: usize,
fail_after: usize
) -> Result<bool>
append the next line, if any, but with some protection against wild stream content:
- don't store chars after the drop_after threshold
- throw an error after the fail_after threshold
Thresholds are in chars, not bytes nor cols nor graphemes. Only difference with next_line is that you pass (and may reuse) the string to fill.
Return Ok(false) when there was no error but nothing to read (stream finished or paused).
This function may return Ok(true) and not have written anything: it means there was an empty line (i.e. next char will be a CR or LF)
pub fn next_line(
&mut self,
drop_after: usize,
fail_after: usize
) -> Result<Option<String>>
[src]
&mut self,
drop_after: usize,
fail_after: usize
) -> Result<Option<String>>
return the next line, if any, but with some protection against wild stream content:
- don't store chars after the drop_after threshold
- throw an error after the fail_after threshold
Thresholds are in chars, not bytes nor cols nor graphemes.
Auto Trait Implementations
impl<R> RefUnwindSafe for CharReader<R> where
R: RefUnwindSafe,
R: RefUnwindSafe,
impl<R> Send for CharReader<R> where
R: Send,
R: Send,
impl<R> Sync for CharReader<R> where
R: Sync,
R: Sync,
impl<R> Unpin for CharReader<R> where
R: Unpin,
R: Unpin,
impl<R> UnwindSafe for CharReader<R> where
R: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,