pub fn decode_from<T, R>(reader: &mut R) -> Result<T>where
T: Deserialize,
R: Read,Available on crate feature
std only.Expand description
Read all remaining bytes from reader and decode them as a single value
of type T.
Use this for whole-buffer reads (a length-prefixed message you have
already extracted from the transport, a small config file, …). For
length-framed protocols where the producer wrote one value and then more
bytes for something else, prefer IoDecoder directly.
§Errors
- Returns
SerialError::TrailingBytesif the reader yielded extra bytes after the value was decoded. - Propagates any
crate::SerialErrorfrom the type’sDeserialize. - Maps any
std::io::Errorfrom the reader intoSerialError::Io.
§Examples
use pack_io::{encode, decode_from};
use std::io::Cursor;
let bytes = encode(&42_u64).unwrap();
let n: u64 = decode_from(&mut Cursor::new(bytes)).unwrap();
assert_eq!(n, 42);