Skip to main content

encode_from_iter

Function encode_from_iter 

Source
pub fn encode_from_iter<T, Len, C>(
    writer: impl Writer,
    src: impl IntoIterator<IntoIter: ExactSizeIterator, Item: Borrow<T::Src>>,
) -> WriteResult<()>
where C: ConfigCore, Len: SeqLen<C>, T: SchemaWrite<C>,
Expand description

Like encode_from_iter_prealloc_check, but skips the preallocation size check.

Use this only when the check is undesirable, or when you have already validated the length yourself via SeqLen::prealloc_check. Because no check is performed here, the produced length may exceed the configured preallocation limit and be rejected on deserialization by SeqLen::read_prealloc_check; prefer encode_from_iter_prealloc_check unless you specifically need to bypass the check.

See encode_from_iter_prealloc_check for details on the wire format and how this relates to FromIntoIterator.

ยงExamples

use wincode::config::{Config, DefaultConfig};
use wincode::containers::encode_from_iter;
use wincode::io::Writer;
use wincode::len::SeqLen;

type C = DefaultConfig;
type Len = <C as Config>::LengthEncoding;

let squares = (0u32..6).map(|i| i * i);

// The caller is responsible for the preallocation check when using this
// variant, so the same configuration accepts the result on deserialization.
assert!(<Len as SeqLen<C>>::prealloc_check::<u32>(squares.len()).is_ok());

let mut buf = Vec::new();
encode_from_iter::<u32, Len, C>(buf.by_ref(), squares).unwrap();

assert_eq!(wincode::deserialize::<Vec<u32>>(&buf).unwrap(), [0, 1, 4, 9, 16, 25]);