pub trait TryUnpack<'a> {
    type Unpacked: Send + Sized + Debug;

    // Required method
    fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>;

    // Provided methods
    fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked> { ... }
    fn try_unpack_from_slice(slice: &'a [u8]) -> Result<Self::Unpacked> { ... }
}
Expand description

Trait for unpacking a spinel-encoded buffer to a specific type.

Similar to TryOwnedUnpack, except that it can also unpack into borrowed types, like &[u8] and &str.

Required Associated Types§

source

type Unpacked: Send + Sized + Debug

The type of the unpacked result. This can be the same as Self, but in some cases it can be different. This is because Self is a marker type, and may not even be Sized. For example, if Self is SpinelUint, then Unpacked would be u32 (because SpinelUint is just a marker trait indicating a variably-sized unsigned integer).

Required Methods§

source

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

Attempts to decode the data at the given iterator into an instance of Self.

Provided Methods§

source

fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

Attempts to decode an item from an array at the given iterator into an instance of Self.

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

Default behavior is the same as try_unpack().

source

fn try_unpack_from_slice(slice: &'a [u8]) -> Result<Self::Unpacked>

Convenience method for unpacking directly from a borrowed slice.

Implementations on Foreign Types§

source§

impl<'a> TryUnpack<'a> for u8

§

type Unpacked = <u8 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for u64

§

type Unpacked = <u64 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for i64

§

type Unpacked = <i64 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for u32

§

type Unpacked = <u32 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for bool

§

type Unpacked = <bool as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a, T> TryUnpack<'a> for Vec<T>where T: TryUnpack<'a>,

§

type Unpacked = Vec<<T as TryUnpack<'a>>::Unpacked, Global>

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for ()

§

type Unpacked = <() as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a, T> TryUnpack<'a> for HashSet<T>where T: TryUnpack<'a>, T::Unpacked: Eq + Hash,

§

type Unpacked = HashSet<<T as TryUnpack<'a>>::Unpacked, RandomState>

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for Ipv6Addr

source§

impl<'a> TryUnpack<'a> for i8

§

type Unpacked = <i8 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a, T, const N: usize> TryUnpack<'a> for [T; N]where T: TryUnpack<'a>,

§

type Unpacked = [<T as TryUnpack<'a>>::Unpacked; N]

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for i32

§

type Unpacked = <i32 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for &'a str

§

type Unpacked = &'a str

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for String

source§

impl<'a> TryUnpack<'a> for i16

§

type Unpacked = <i16 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for u16

§

type Unpacked = <u16 as TryOwnedUnpack>::Unpacked

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

impl<'a> TryUnpack<'a> for &'a [u8]

§

type Unpacked = &'a [u8]

source§

fn try_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

source§

fn try_array_unpack(iter: &mut Iter<'a, u8>) -> Result<Self::Unpacked>

Implementors§

source§

impl<'a> TryUnpack<'a> for &'a EUI48

Borrowed unpack for EUI48

§

type Unpacked = &'a EUI48

source§

impl<'a> TryUnpack<'a> for &'a EUI64

Borrowed unpack for EUI64

§

type Unpacked = &'a EUI64

source§

impl<'a> TryUnpack<'a> for SpinelUint

source§

impl<'a> TryUnpack<'a> for EUI48

source§

impl<'a> TryUnpack<'a> for EUI64