[][src]Struct char_reader::CharReader

pub struct CharReader<R: Read> { /* fields omitted */ }

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]

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]

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

impl<R> Send for CharReader<R> where
    R: Send

impl<R> Sync for CharReader<R> where
    R: Sync

impl<R> Unpin for CharReader<R> where
    R: Unpin

impl<R> UnwindSafe for CharReader<R> where
    R: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.