Trait toad_msg::TryIntoBytes
source · pub trait TryIntoBytes {
type Error;
// Required method
fn try_into_bytes<C: Array<Item = u8>>(self) -> Result<C, Self::Error>;
}
Expand description
Trait allowing fallible conversion into bytes
Required Associated Types§
Required Methods§
sourcefn try_into_bytes<C: Array<Item = u8>>(self) -> Result<C, Self::Error>
fn try_into_bytes<C: Array<Item = u8>>(self) -> Result<C, Self::Error>
Try to convert into a collection of bytes
use tinyvec::ArrayVec;
use toad_msg::{Message, OptNumber, OptValue, TryIntoBytes};
type OptionValue = OptValue<ArrayVec<[u8; 128]>>;
type OptionMapEntry = (OptNumber, ArrayVec<[OptionValue; 4]>);
type OptionMap = ArrayVec<[OptionMapEntry; 16]>;
type Payload = ArrayVec<[u8; 1024]>;
let arrayvec_message = Message::<Payload, OptionMap> {
// ...
};
let bytes: tinyvec::ArrayVec<[u8; 1024]> = arrayvec_message.try_into_bytes().unwrap();
// This one uses Vec
let vec_message = toad_msg::alloc::Message {
// ...
};
let bytes: Vec<u8> = vec_message.try_into_bytes().unwrap();