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§
Provided Methods§
Sourcefn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>
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().
Sourcefn array_pack_len(&self) -> Result<usize>
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().
Sourcefn try_packed(&self) -> Result<Vec<u8>>
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.