pub fn from_reader<R: Read, T: BorshDeserialize>(reader: &mut R) -> Result<T>
Expand description
Deserializes an object from a reader.
ยงExample
use borsh::{BorshDeserialize, BorshSerialize, from_reader, to_vec};
/// derive is only available if borsh is built with `features = ["derive"]`
#[derive(BorshSerialize, BorshDeserialize, PartialEq, Debug)]
struct MyStruct {
a: u64,
b: Vec<u8>,
}
let original = MyStruct { a: 10, b: vec![1, 2, 3] };
let encoded = to_vec(&original).unwrap();
let decoded = from_reader::<_, MyStruct>(&mut encoded.as_slice()).unwrap();
assert_eq!(original, decoded);