Skip to main content

decode_from_reader

Function decode_from_reader 

Source
pub fn decode_from_reader<D: Decode, R: Read>(reader: R) -> Result<(D, usize)>
Available on crate feature std only.
Expand description

Decode a value from any std::io::Read implementor using the standard configuration.

Returns (value, bytes_read). This is a convenience wrapper that uses the default configuration and tracks the number of bytes consumed.

ยงExamples

use std::io::Cursor;
let bytes = oxicode::encode_to_vec(&42u32).expect("encode");
let cursor = Cursor::new(&bytes);
let (decoded, n): (u32, _) = oxicode::decode_from_reader(cursor).expect("decode");
assert_eq!(decoded, 42u32);
assert_eq!(n, bytes.len());