ReadExt

Trait ReadExt 

Source
pub trait ReadExt {
    // Required methods
    fn try_read_exact(
        &mut self,
        buf: &mut [u8],
        pos_cb: impl FnMut(usize),
    ) -> Result<(), Error>;
    fn try_drain(
        &mut self,
        len: usize,
        pos_cb: impl FnMut(usize),
    ) -> Result<(), Error>;
}
Expand description

An extension for Read

Required Methods§

Source

fn try_read_exact( &mut self, buf: &mut [u8], pos_cb: impl FnMut(usize), ) -> Result<(), Error>

Tries to fill buf completely and calls the position callback pos_cb with the amount of bytes read on every successful read call

Note: This function behaves like read_exact, except that you will never loose state in case of an incomplete read - if the error is non-fatal (like TimedOut), you can always try again later if nothing happened

Source

fn try_drain( &mut self, len: usize, pos_cb: impl FnMut(usize), ) -> Result<(), Error>

Tries to consume len bytes and calls the position callback pos_cb with the amount of bytes drained on every successful read call

Note: This function behaves similar to read_exact (without buffer), except that you will never loose state in case of an incomplete write - if the error is non-fatal (like TimedOut), you can always try again later if nothing happened

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> ReadExt for T