Function tycho::to_bytes[][src]

pub fn to_bytes<T: Serialize>(o: &T) -> Result<Vec<u8>, SerializeError>

Serialize into bytes

use tycho::{Element, Value, decode, to_bytes};
use serde::Serialize;

#[derive(Serialize, Debug)]
pub struct Example {
    foo: String,
    bar: u8,
    baz: bool
}

let element = Example {
    foo: "Hello World".to_string(),
    bar: 42,
    baz: true
};

let bytes = to_bytes(&element).unwrap();
// assert_eq!(bytes, vec![64, 3, 3, 102, 111, 111, 29, 11, 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 3, 98, 97, 114, 17, 42, 3, 98, 97, 122, 16, 1])