Skip to main content

decode_from

Function decode_from 

Source
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

§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);