Function tycho::from_bytes[][src]

pub fn from_bytes<D: DeserializeOwned>(b: &[u8]) -> TychoResult<D>

Deserialize tycho bytes into a serde deserializable object. (requires serde_support)

use serde::Deserialize;
use tycho::from_bytes;

// Create a serializable serde structure.
#[derive(Deserialize, PartialEq, Debug)]
pub struct Example {
    foo: String
}

// Example bytes
let bytes = vec![5, 9, 102, 111, 111, 0, 1, 2, 2, 72, 105];

// Deserialize bytes
let data: Example = from_bytes(&bytes).unwrap();

assert_eq!(data, Example { foo: "Hi".to_string() })