Packer

Trait 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.

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.

Implementations on Foreign Types§

Source§

impl Packer for Vec<u8>

Source§

type Error = Infallible

Source§

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

Source§

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

Source§

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

Source§

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>

Implementors§