serialize

Function serialize 

Source
pub fn serialize<T>(src: &T) -> WriteResult<Vec<u8>>
where T: SchemaWrite<Src = T> + ?Sized,
Available on crate feature alloc only.
Expand description

Serialize a type into a Vec of bytes.

This is a “simplified” version of Serialize::serialize that requires the T::Src to be T. In other words, a schema type that serializes to itself.

This helper exists to match the expected signature of serde’s Serialize, where types that implement Serialize serialize themselves. This will be true of a large number of schema types, but wont, for example, for specialized container structures.

§Examples

let vec: Vec<u8> = vec![1, 2, 3];
let bytes = wincode::serialize(&vec).unwrap();