Packable

Trait Packable 

Source
pub trait Packable {
    type Error: Debug;

    // Required methods
    fn packed_len(&self) -> usize;
    fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>;
    fn unpack_inner<R: Read + ?Sized, const CHECK: bool>(
        reader: &mut R,
    ) -> Result<Self, Self::Error>
       where Self: Sized;

    // Provided methods
    fn pack_new(&self) -> Vec<u8>  { ... }
    fn unpack<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Self::Error>
       where Self: Sized { ... }
    fn unpack_unchecked<R: Read + ?Sized>(
        reader: &mut R,
    ) -> Result<Self, Self::Error>
       where Self: Sized { ... }
}
Expand description

A trait to pack and unpack types to and from bytes.

Required Associated Types§

Source

type Error: Debug

Associated error type.

Required Methods§

Source

fn packed_len(&self) -> usize

Returns the length of the packed bytes.

Source

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Packs the instance to bytes and writes them to the passed writer.

Source

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Reads bytes from the passed reader and unpacks them into an instance.

Provided Methods§

Source

fn pack_new(&self) -> Vec<u8>

Packs the instance to bytes and writes them to a newly allocated vector.

Source

fn unpack<R: Read + ?Sized>(reader: &mut R) -> Result<Self, Self::Error>
where Self: Sized,

Reads bytes from the passed reader and unpacks them into an instance. Applies syntactic checks.

Source

fn unpack_unchecked<R: Read + ?Sized>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Reads bytes from the passed reader and unpacks them into an instance. Doesn’t apply syntactic checks.

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 Packable for bool

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for i8

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for i16

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for i32

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for i64

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for i128

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for u8

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for u16

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for u32

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for u64

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl Packable for u128

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl<P> Packable for Vec<P>
where P: Packable, P::Error: From<Error>,

Source§

type Error = <P as Packable>::Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl<P: Packable> Packable for Option<P>

Source§

type Error = OptionError<<P as Packable>::Error>

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Source§

impl<const N: usize> Packable for [u8; N]

Source§

type Error = Error

Source§

fn packed_len(&self) -> usize

Source§

fn pack<W: Write>(&self, writer: &mut W) -> Result<(), Self::Error>

Source§

fn unpack_inner<R: Read + ?Sized, const CHECK: bool>( reader: &mut R, ) -> Result<Self, Self::Error>
where Self: Sized,

Implementors§