[][src]Function ordcode::ser_to_vec_ordered

pub fn ser_to_vec_ordered<T: ?Sized>(value: &T, order: Order) -> Result<Vec<u8>> where
    T: Serialize

Serialize value into byte vector

Example


#[derive(serde_derive::Serialize)]
struct Foo(u16, String);
let foo = Foo(1, "abc".to_string());

let buf = ser_to_vec_ordered(&foo, Order::Ascending).unwrap();
assert_eq!(&buf[2..5], b"abc");
assert_eq!(buf[5], 7); // last byte is string length (3) in varint encoding