Trait spinel_pack::TryPackAs
source · pub trait TryPackAs<Marker: ?Sized> {
// Required methods
fn try_pack_as<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>;
fn pack_as_len(&self) -> Result<usize>;
}
Expand description
Trait implemented by data types that support being serialized to a specific spinel-based byte encoding, based on the marker type.
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 TryPackAs<[u8]>
and TryPackAs<SpinelDataWlen>
for handling the D
and d
Spinel field formats respectively when
serializing.
Required Methods§
sourcefn try_pack_as<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>
fn try_pack_as<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>
Uses Spinel encoding to serialize to a given std::io::Write
reference as the
Spinel type identified by Marker
.
sourcefn pack_as_len(&self) -> Result<usize>
fn pack_as_len(&self) -> Result<usize>
Calculates how many bytes this type will use when serialized.
Object Safety§
This trait is not object safe.