TryIntoBytes

Trait 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§

Source

fn try_into_bytes<C: Array<Item = u8>>(self) -> Result<C, Self::Error>

Try to convert into a collection of bytes

use kwap_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 = kwap_msg::ArrayVecMessage::<0, 0, 0> {
  // ...
};

let bytes: tinyvec::ArrayVec<[u8; 1024]> = arrayvec_message.try_into_bytes().unwrap();

// This one uses Vec
let vec_message = kwap_msg::VecMessage {
  // ...
};

let bytes: Vec<u8> = vec_message.try_into_bytes().unwrap();

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.

Implementors§

Source§

impl<P: Array<Item = u8>, O: Array<Item = u8>, Os: Array<Item = Opt<O>>> TryIntoBytes for Message<P, O, Os>

Source§

type Error = MessageToBytesError