Function postcard::to_allocvec [−][src]
pub fn to_allocvec<T: ?Sized>(value: &T) -> Result<Vec<u8>> where
T: Serialize + ?Sized,
Expand description
Serialize a T
to an alloc::vec::Vec<u8>
. Requires the alloc
feature.
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'!']);