pub trait Unpacker: Sized {
    type Error;

    // Required method
    fn unpack_bytes<B: AsMut<[u8]>>(
        &mut self,
        bytes: B
    ) -> Result<(), Self::Error>;

    // Provided methods
    fn ensure_bytes(&self, _len: usize) -> Result<(), Self::Error> { ... }
    fn read_bytes(&self) -> Option<usize> { ... }
}
Expand description

A type that can unpack any value that implements Packable.

Required Associated Types§

source

type Error

An error type representing any error related to reading bytes.

Required Methods§

source

fn unpack_bytes<B: AsMut<[u8]>>(&mut self, bytes: B) -> Result<(), Self::Error>

Reads a sequence of bytes from the Unpacker. This sequence must be long enough to fill bytes completely. This method must fail if the unpacker does not have enough bytes to fulfill the request.

Provided Methods§

source

fn ensure_bytes(&self, _len: usize) -> Result<(), Self::Error>

Tries to guarantee that the Unpacker has at least len bytes.

This method must fail if and only if it is certain that there are not enough bytes and it is allowed to return Ok(()) in any other case.

source

fn read_bytes(&self) -> Option<usize>

Returns the exact number of read bytes if possible.

Implementations on Foreign Types§

source§

impl<U: Unpacker + ?Sized> Unpacker for &mut U

§

type Error = <U as Unpacker>::Error

source§

fn unpack_bytes<B: AsMut<[u8]>>(&mut self, bytes: B) -> Result<(), Self::Error>

source§

fn ensure_bytes(&self, len: usize) -> Result<(), Self::Error>

source§

fn read_bytes(&self) -> Option<usize>

Implementors§