[][src]Trait genio::ext::ReadExt

pub trait ReadExt: Read {
    fn read_ext<'a, 'b>(
        &'a mut self,
        buf: &'b mut [u8]
    ) -> Result<ReadResult<'b>, Self::ReadError>; }

After reading to buffer, it's often useful to adjust the slice. Also, reading may be done in loop, which ends when reader has no more data.

To make handling of these cases easier, one can use read_ext method which returns ReadResult instead of usize.

Thanks to it you may write:

let mut buf = [0; 1024];
while let Bytes(bytes) = reader.read_ext(&mut buf)? {
    // Process  bytes here.
}

instead of this:

let mut buf = [0; 1024];
loop {
    let len = reader.read(&mut buf)?;
    if len == 0 {
        break;
    }

    let bytes = &mut buf[..len];
    // Process bytes here.
}

Required methods

fn read_ext<'a, 'b>(
    &'a mut self,
    buf: &'b mut [u8]
) -> Result<ReadResult<'b>, Self::ReadError>

Reads from the reader and converts the result.

Loading content...

Implementors

impl<R: Read + ?Sized> ReadExt for R[src]

Loading content...