Skip to main content

encode_iter_to_vec

Function encode_iter_to_vec 

Source
pub fn encode_iter_to_vec<E: Encode, I: IntoIterator<Item = E>>(
    iter: I,
) -> Result<Vec<u8>>
Available on crate feature alloc only.
Expand description

Encode an iterator of items as a length-prefixed sequence into a Vec<u8>.

Internally collects the iterator to determine the length (required by the wire format), then encodes using the same format as Vec<T>. The result is byte-for-byte identical to encoding a Vec<E> containing the same elements.

ยงExamples

let items = [1u32, 2, 3, 4, 5];
let encoded = oxicode::encode_iter_to_vec(items.iter().copied()).expect("encode");
let (decoded, _): (Vec<u32>, _) = oxicode::decode_from_slice(&encoded).expect("decode");
assert_eq!(decoded, vec![1, 2, 3, 4, 5]);