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§
Sourcefn try_read_exact(&mut self, buffer: &mut [u8]) -> Result<usize, Box<dyn Error>>
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.
Sourcefn skip(&mut self, bytes: usize) -> Result<usize, Box<dyn Error>>
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
Sourcefn stream_to<W>(
&mut self,
w: &mut W,
buffer_size: Option<usize>,
observer: Option<Box<dyn StreamObserver>>,
) -> 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>>
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.
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.