Trait EhRead

Source
pub trait EhRead: Read {
    // Provided methods
    fn try_read_exact(
        &mut self,
        buffer: &mut [u8],
    ) -> Result<usize, Box<dyn Error>> { ... }
    fn skip(&mut self, bytes: usize) -> Result<usize, Box<dyn Error>> { ... }
    fn stream_to<W>(
        &mut self,
        w: &mut W,
        buffer_size: Option<usize>,
        observer: Option<Box<dyn StreamObserver>>,
    ) -> Result<usize, Box<dyn Error>>
       where W: Write + Sized { ... }
    fn stream_to_with_buffer<W>(
        &mut self,
        w: &mut W,
        buffer: &mut [u8],
        observer: Option<Box<dyn StreamObserver>>,
    ) -> Result<usize, Box<dyn Error>>
       where W: Write + Sized { ... }
}
Expand description

Enhanced Reader for std::io::Read It provides convenient methods for exact reading without throwing error It allow you to send it to writer

Provided Methods§

Source

fn try_read_exact(&mut self, buffer: &mut [u8]) -> Result<usize, Box<dyn Error>>

Try to fully read to fill the buffer, similar to read_exact, However, this method never throw errors on error on EOF. On EOF, it also returns Ok(size) but size might be smaller than available buffer. When size is smaller than buffer size, it must be EOF.

Upon EOF, you may read again, but you will get EOF anyway with the EOF error.

Source

fn skip(&mut self, bytes: usize) -> Result<usize, Box<dyn Error>>

Skip bytes from the reader. Return the actual size skipped or the error. If EOF reached before skip is complete, UnexpectedEOF error is returned. On success, the size must be equal to the input bytes

Source

fn stream_to<W>( &mut self, w: &mut W, buffer_size: Option<usize>, observer: Option<Box<dyn StreamObserver>>, ) -> Result<usize, Box<dyn Error>>
where W: Write + Sized,

Copy all content until EOF to Write. Using buffer_size buffer. If not given, 4096 is used. If buffer_size is Some(0), 4096 is used

Return the number of bytes copied, or any error encountered.

If error is EOF, then error is not returned and size would be 0.

Source

fn stream_to_with_buffer<W>( &mut self, w: &mut W, buffer: &mut [u8], observer: Option<Box<dyn StreamObserver>>, ) -> Result<usize, Box<dyn Error>>
where W: Write + Sized,

Same as stream_to, but use externally provided buffer

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> EhRead for T
where T: Read,

Blanked implementation for EhRead for all Read for free

You can use EhRead functions on all Read’s implementations as long as you use this library and import EhRead trait.