Skip to main content

read_msgpack

Function read_msgpack 

Source
pub fn read_msgpack<R: Read, T: FromMessagePackOwned>(reader: R) -> Result<T>
Expand description

Deserializes a value of type T from the I/O stream.

§Errors

Deserialization can fail if T’s implementation of FromMessagePack returns an error, or if the underlying I/O operation fails.

§Examples

#[derive(zerompk::FromMessagePack)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let mut file = std::fs::File::open("point.msgpack").unwrap();
    let point: Point = zerompk::read_msgpack(&mut file).unwrap();
    assert_eq!(point.x, 1);
    assert_eq!(point.y, 2);
}