pub trait LineRead {
    // Required methods
    fn eof(&self) -> bool;
    fn read_once(&mut self) -> Result<bool, Error>;
    fn lines_get(&mut self) -> Vec<String>;
    fn has_lines(&mut self) -> bool;

    // Provided method
    fn read_available(&mut self) -> Result<(), Error> { ... }
}
Expand description

Trait for buffered non-blocking readeres that return only complete lines.

This trait can be used to create a collection of LineReaders that use different underlying types, by using trait objects.

Required Methods§

source

fn eof(&self) -> bool

Returns true if we have already reached EOF in the underlying Read object.

Once this function returns true, read_once and read_available stop having any effect, they return immediately.

The buffer may have complete lines, so a last call to lines_get is recommended.

source

fn read_once(&mut self) -> Result<bool, Error>

Performs a single read operation on the underlying Read object.

Returns Ok(true) if we have already reached EOF, Ok(false) if we have not. That doesn’t mean that there is more data available to read immediately, it just means that the file descriptor is still open.

This function can also return an std::io::Error if one is found, or if an invalid UTF-8 sequence is read.

source

fn lines_get(&mut self) -> Vec<String>

Returns the internal line buffer.

This method transfers ownership of the buffer to the caller, effectively clearing the internal buffer.

source

fn has_lines(&mut self) -> bool

Returns true if there are complete lines in the internal buffer.

If this returns true, Self::lines_get won’t return an empty vector.

Provided Methods§

source

fn read_available(&mut self) -> Result<(), Error>

Reads all available data into the internal line buffer, or at least until a complete line is available.

This method just calls Self::read_once until it returns false or Self::has_lines returns true.

Implementors§