Skip to main content

decode_iter_from_slice

Function decode_iter_from_slice 

Source
pub fn decode_iter_from_slice<T: Decode>(
    src: &[u8],
) -> Result<DecodeIter<T, DecoderImpl<SliceReader<'_>, Configuration>>>
Available on crate feature alloc only.
Expand description

Decode a sequence lazily, yielding items one at a time without loading all into memory.

Reads the length prefix from the encoded bytes (same wire format as Vec<T>), then returns an iterator that decodes items on demand. More memory-efficient than decode_from_slice for large collections.

Each item yielded is Result<T>, allowing per-item error handling.

ยงExamples

let data = vec![1u32, 2, 3, 4, 5];
let encoded = oxicode::encode_to_vec(&data).expect("encode");
let sum: u32 = oxicode::decode_iter_from_slice::<u32>(&encoded)
    .expect("init")
    .filter_map(|r| r.ok())
    .sum();
assert_eq!(sum, 15);