Function postcard::to_allocvec

source ·
pub fn to_allocvec<T>(value: &T) -> Result<Vec<u8>>
where T: Serialize + ?Sized,
Expand description

Serialize a T to an alloc::vec::Vec<u8>.

§Example

use postcard::to_allocvec;

let ser: Vec<u8> = to_allocvec(&true).unwrap();
assert_eq!(ser.as_slice(), &[0x01]);

let ser: Vec<u8> = to_allocvec("Hi!").unwrap();
assert_eq!(ser.as_slice(), &[0x03, b'H', b'i', b'!']);