spinel_pack

Trait TryPack

Source
pub trait TryPack {
    // Required methods
    fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>;
    fn pack_len(&self) -> Result<usize>;

    // Provided methods
    fn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize> { ... }
    fn array_pack_len(&self) -> Result<usize> { ... }
    fn try_packed(&self) -> Result<Vec<u8>> { ... }
}
Expand description

Trait implemented by data types that support being serialized to a spinel-based byte encoding.

Required Methods§

Source

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Uses Spinel encoding to serialize to a given std::io::Write reference.

Source

fn pack_len(&self) -> Result<usize>

Calculates how many bytes this type will use when serialized.

Provided Methods§

Source

fn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Uses Spinel array encoding to serialize to a given std::io::Write reference.

Array encoding is occasionally different than single-value encoding, hence the need for a separate method.

Default behavior is the same as try_pack().

Source

fn array_pack_len(&self) -> Result<usize>

Calculates how many bytes this type will use when serialized into an array.

Array encoding is occasionally different than single-value encoding, hence the need for a separate method.

Default behavior is the same as pack_len().

Source

fn try_packed(&self) -> Result<Vec<u8>>

Convenience method which serializes to a new Vec<u8>.

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 TryPack for &str

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for bool

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for i8

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for i16

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for i32

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for i64

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for str

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for u8

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for u16

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for u32

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for u64

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for ()

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for String

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl TryPack for Ipv6Addr

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>

Source§

impl<T: TryPack> TryPack for &[T]

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Source§

fn array_pack_len(&self) -> Result<usize>

Source§

fn try_array_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Source§

impl<T: TryPack> TryPack for Vec<T>
where for<'a> &'a [T]: TryPack,

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Source§

fn array_pack_len(&self) -> Result<usize>

Source§

fn try_array_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Source§

impl<T: TryPack> TryPack for HashSet<T>

Source§

fn pack_len(&self) -> Result<usize>

Source§

fn try_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Source§

fn array_pack_len(&self) -> Result<usize>

Source§

fn try_array_pack<B: Write + ?Sized>(&self, buffer: &mut B) -> Result<usize>

Implementors§