Trait toad_msg::TryIntoBytes
source · pub trait TryIntoBytes {
type Error;
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 toad_msg::TryIntoBytes;
// This one has static params that allocates space on the static
// and uses `tinyvec::ArrayVec` as the byte buffer backing structure
let arrayvec_message = toad_msg::ArrayVecMessage::<0, 0, 0> {
// ...
};
let bytes: tinyvec::ArrayVec<[u8; 1024]> = arrayvec_message.try_into_bytes().unwrap();
// This one uses Vec
let vec_message = toad_msg::VecMessage {
// ...
};
let bytes: Vec<u8> = vec_message.try_into_bytes().unwrap();