ReadExt

Trait ReadExt 

Source
pub trait ReadExt: Read {
    // Provided methods
    fn read_chunks(&mut self, n: usize) -> ReadChunks<'_, Self> { ... }
    fn keep_reading(&mut self, buf: &mut [u8]) -> Result<usize> { ... }
}
Expand description

Trait that extends any type implementing Read with ReadChunks

Provided Methods§

Source

fn read_chunks(&mut self, n: usize) -> ReadChunks<'_, Self>

Returns a lending iterator that yields chunks of size n until the end of the reader.

This method will allocate n bytes once.

(This is NOT a stdlib candidate.)

Source

fn keep_reading(&mut self, buf: &mut [u8]) -> Result<usize>

Attempts to “keep reading” to fill up buf, by ignoring ErrorKind::Interrupted errors, and continuously reading from the backing reader until Ok(0) or a different error is encountered.

§Errors

If this function encounters ErrorKind::Interrupted it will continue to attempt to fill the buffer until a different error is encountered, the buffer is filled, or the reader returns Ok(0).

If a different read error occurs, this function will return the error, and the contents of buf is unspecified.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Read + ?Sized> ReadExt for T