[][src]Function rmp_serde::decode::from_read_ref

pub fn from_read_ref<'a, R: ?Sized, T>(rd: &'a R) -> Result<T, Error> where
    R: AsRef<[u8]>,
    T: Deserialize<'a>, 

Deserialize an instance of type T from a reference I/O reader of MessagePack.

Deserialization will be performed in zero-copy manner whenever it is possible, borrowing the data from the reader itself. For example, strings and byte-arrays won't be not copied.

Errors

This conversion can fail if the structure of the Value does not match the structure expected by T. It can also fail if the structure is correct but T's implementation of Deserialize decides that something is wrong with the data, for example required struct fields are missing.

Examples

extern crate rmp_serde as rmps;

// Encoded `["Bobby", 8]`.
let buf = [0x92, 0xa5, 0x42, 0x6f, 0x62, 0x62, 0x79, 0x8];

#[derive(Debug, Deserialize, PartialEq)]
struct Dog<'a> {
   name: &'a str,
   age: u8,
}

assert_eq!(Dog { name: "Bobby", age: 8 }, rmps::from_read_ref(&buf).unwrap());