Trait packable::packer::Packer

source ·
pub trait Packer {
    type Error;

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

    // Provided method
    fn written_bytes(&self) -> Option<usize> { ... }
}
Expand description

A type that can pack any value that implements Packable.

Required Associated Types§

source

type Error

An error type representing any error related to writing bytes.

Required Methods§

source

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

Writes a sequence of bytes into the Packer. The totality of bytes must be written into the packer. This method must fail if the packer does not have enough space to fulfill the request.

Provided Methods§

source

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

Returns the exact number of written bytes if possible.

Implementations on Foreign Types§

source§

impl<P: Packer + ?Sized> Packer for &mut P

§

type Error = <P as Packer>::Error

source§

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

source§

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

source§

impl Packer for Vec<u8>

§

type Error = Infallible

source§

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

source§

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

Implementors§