Function tycho::from_bytes[][src]

pub fn from_bytes<T: DeserializeOwned>(
    data: Vec<u8>
) -> Result<T, DeserializeError>

Deserialize from bytes

use tycho::{Element, Value, decode, from_bytes};
use serde::Deserialize;

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

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

assert_eq!(
    element,
    Example {
        foo: "Hello World".to_string(),
        bar: 42,
        baz: true
    }
)