Skip to main content

decode_from_reader_with_config

Function decode_from_reader_with_config 

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

Decode a value from any std::io::Read using a custom configuration.

Returns (value, bytes_read). This is a convenience wrapper that tracks the number of bytes consumed from the reader.

ยง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_with_config(
    cursor,
    oxicode::config::standard(),
)
.expect("decode");
assert_eq!(decoded, 42u32);
assert_eq!(n, bytes.len());