Trait spinel_pack::TryUnpackAs
source · pub trait TryUnpackAs<'a, Marker: ?Sized>: Sized {
// Required method
fn try_unpack_as(iter: &mut Iter<'a, u8>) -> Result<Self>;
// Provided method
fn try_unpack_as_from_slice(slice: &'a [u8]) -> Result<Self> { ... }
}
Expand description
Trait for unpacking a spinel-encoded buffer to a specific type when the field type is known.
The generic parameter Marker
is effectiely a part of the name of the
trait and is not used directly by the trait. Types may implement more than
one instance of this trait, each with a different marker type.
For example, structs that use the spinel_packed
attribute macro
will implement both TryUnpackAs<[u8]>
and TryUnpackAs<SpinelDataWlen>
for handling the D
and d
Spinel field formats respectively when
deserializing.
Required Methods§
sourcefn try_unpack_as(iter: &mut Iter<'a, u8>) -> Result<Self>
fn try_unpack_as(iter: &mut Iter<'a, u8>) -> Result<Self>
Attempts to decode the data (with a format determined by Marker
) at the given
iterator into an instance of Self
.
Provided Methods§
sourcefn try_unpack_as_from_slice(slice: &'a [u8]) -> Result<Self>
fn try_unpack_as_from_slice(slice: &'a [u8]) -> Result<Self>
Convenience method for unpacking directly from a borrowed slice.
Object Safety§
This trait is not object safe.