pub fn from_bytes<'a, T>(s: &'a [u8]) -> Result<(T, &'a [u8])>where
T: Deserialize<'a>,Expand description
Return a deserialized value and trailing bytes.
§Example
Simple Usage:
ⓘ
let serialized = to_bytes(value).unwrap();
// Ignore the size
let (new_value, _trailing_bytes) = from_bytes::<T>(&serialized[4..]).unwrap();
assert_eq!(value, new_value);Replace T with type of value.
More complicated one (sending over socket):
ⓘ
let buffer = [0, 0, 0, 4];
let (size: u32, _trailing_bytes) = from_bytes(&buffer).unwrap();
let buffer = [0, 0, 4, 0];
let (val: <T>, _trailing_bytes) = from_bytes(&buffer).unwrap();Replace T with your own type.