I would suggest bincode .
It provides encode() and decode() functions that work with anything with RustcEncodable and RustcDecodable traits, which can usually be #[derive] d, and return a Vec<u8> .
It has a few quirks ( isize and usize become i64 and u64 , for example), but basically they improve portability, and it works the way you expected.
Leo tindall
source share