Skip to main content

FromIntoIterator

Struct FromIntoIterator 

Source
pub struct FromIntoIterator<Coll, Len>(/* private fields */);
Expand description

A generic sequence schema for custom collections that implement FromIterator (for reading) and whose references implement IntoIterator with an ExactSizeIterator (for writing).

Works for both element sequences and key-value maps:

  • For element collections (sets, ordered sets, etc.) whose reference iterators yield &T, the schema for T is used directly.
  • For map-like collections whose reference iterators yield (&K, &V) pairs, the pair itself acts as the schema (automatically satisfied when K and V implement SchemaWrite<C>).

Intended for external collection types that cannot have a dedicated schema impl added directly. Unlike Vec, VecDeque, and BinaryHeap, this container relies on the collection’s FromIterator impl rather than writing directly into preallocated memory.

For manual SchemaWrite implementations that emit a sequence from an ad-hoc iterator rather than a concrete collection, see encode_from_iter_prealloc_check (and its check-skipping counterpart encode_from_iter).

§Allocation efficiency

During deserialization, the iterator passed to FromIterator has a precise size_hint matching the number of elements produced, unless a read error is encountered. Collections whose FromIterator implementation uses the size hint to preallocate capacity will allocate optimally. Collections that do not use it will not benefit.

§Examples

ⓘ
use some_crate::{IndexSet, MyMap};
use wincode::{SchemaRead, SchemaWrite, containers::FromIntoIterator, len::BincodeLen};

#[derive(SchemaRead, SchemaWrite)]
struct MyData {
    #[wincode(with = "FromIntoIterator<IndexSet<u32>, BincodeLen>")]
    items: IndexSet<u32>,
    #[wincode(with = "FromIntoIterator<MyMap<u32, u64>, BincodeLen>")]
    map: MyMap<u32, u64>,
}

Trait Implementations§

Source§

impl<'de, Coll, Len, C: ConfigCore> SchemaRead<'de, C> for FromIntoIterator<Coll, Len>
where Len: SeqLen<C>, Coll: IntoIterator<Item: SchemaRead<'de, C>> + FromIterator<<Coll::Item as SchemaRead<'de, C>>::Dst>,

Source§

type Dst = Coll

Source§

fn read(reader: impl Reader<'de>, dst: &mut MaybeUninit<Coll>) -> ReadResult<()>

Read into dst from reader. Read more
Source§

const TYPE_META: TypeMeta = TypeMeta::Dynamic

Metadata about the type’s serialization. Read more
Source§

fn get(reader: impl Reader<'de>) -> ReadResult<Self::Dst>

Read Self::Dst from reader into a new Self::Dst.
Source§

impl<Coll, Len, C: ConfigCore> SchemaWrite<C> for FromIntoIterator<Coll, Len>
where Len: SeqLen<C>, Coll: IntoIterator, for<'a> &'a Coll: IntoIterator<Item: SchemaWrite<C>, IntoIter: ExactSizeIterator>, for<'a> <&'a Coll as IntoIterator>::Item: Borrow<<<&'a Coll as IntoIterator>::Item as SchemaWrite<C>>::Src>,

Source§

type Src = Coll

Source§

fn size_of(src: &Coll) -> WriteResult<usize>

Get the serialized size of Self::Src. Read more
Source§

fn write(writer: impl Writer, src: &Coll) -> WriteResult<()>

Write Self::Src to writer.
Source§

const TYPE_META: TypeMeta = TypeMeta::Dynamic

Metadata about the type’s serialization. Read more

Auto Trait Implementations§

§

impl<Coll, Len> Freeze for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> RefUnwindSafe for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> Send for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> Sync for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> Unpin for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> UnsafeUnpin for FromIntoIterator<Coll, Len>

§

impl<Coll, Len> UnwindSafe for FromIntoIterator<Coll, Len>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<'de, T, C> Deserialize<'de, C> for T
where C: Config, T: SchemaRead<'de, C>,

Source§

fn deserialize(src: &'de [u8], config: C) -> ReadResult<Self::Dst>

Deserialize the input bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, config: C, ) -> ReadResult<()>

Deserialize the input bytes into dst.
Source§

impl<'de, T> Deserialize<'de> for T
where T: SchemaRead<'de, Configuration>,

Source§

fn deserialize(src: &'de [u8]) -> ReadResult<Self::Dst>

Deserialize the input src bytes into a new Self::Dst.
Source§

fn deserialize_into( src: &'de [u8], dst: &mut MaybeUninit<Self::Dst>, ) -> ReadResult<()>

Deserialize the input src bytes into dst.
Source§

impl<T> DeserializeOwned for T

Source§

fn deserialize_from<'de>( src: impl Reader<'de>, ) -> ReadResult<<Self as SchemaRead<'de, DefaultConfig>>::Dst>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<<Self as SchemaRead<'de, DefaultConfig>>::Dst>, ) -> ReadResult<()>

Deserialize from the given Reader into dst.
Source§

impl<T, C> DeserializeOwned<C> for T
where C: Config, T: SchemaReadOwned<C>,

Source§

fn deserialize_from<'de>( src: impl Reader<'de>, ) -> ReadResult<<Self as SchemaRead<'de, C>>::Dst>

Deserialize from the given Reader into a new Self::Dst.
Source§

fn deserialize_from_into<'de>( src: impl Reader<'de>, dst: &mut MaybeUninit<<Self as SchemaRead<'de, C>>::Dst>, ) -> ReadResult<()>

Deserialize from the given Reader into dst.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, C> SchemaReadOwned<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C>,

Source§

impl<T> Serialize for T

Source§

fn serialize(src: &Self::Src) -> WriteResult<Vec<u8>>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into(dst: impl Writer, src: &Self::Src) -> WriteResult<()>

Serialize a serializable type into the given byte buffer. Read more
Source§

fn serialized_size(src: &Self::Src) -> WriteResult<u64>

Get the size in bytes of the type when serialized.
Source§

impl<T, C> Serialize<C> for T
where C: Config, T: SchemaWrite<C> + ?Sized,

Source§

fn serialize(src: &Self::Src, config: C) -> WriteResult<Vec<u8>>

Serialize a serializable type into a Vec of bytes.
Source§

fn serialize_into( dst: impl Writer, src: &Self::Src, config: C, ) -> WriteResult<()>

Serialize a serializable type into the given Writer. Read more
Source§

fn serialized_size(src: &Self::Src, config: C) -> WriteResult<u64>

Get the size in bytes of the type when serialized.
Source§

impl<T, Target, C> TagEncoding<C> for T
where C: ConfigCore, T: for<'de> SchemaRead<'de, C, Dst = Target> + SchemaWrite<C, Src = Target> + 'static, Target: TryFrom<u32>, u32: TryFrom<Target>,

Source§

type Target = Target

Source§

fn try_from_u32( value: u32, ) -> Result<<T as TagEncoding<C>>::Target, TagEncodingOverflow>

Convert a u32 to the encoding target.
Source§

fn try_into_u32( x: <T as TagEncoding<C>>::Target, ) -> Result<u32, TagEncodingOverflow>

Convert the encoding target to a u32.
Source§

fn size_of_from_u32(value: u32) -> WriteResult<usize>

Get the size of the encoding target from the given u32. Read more
Source§

fn write_from_u32(writer: impl Writer, value: u32) -> WriteResult<()>

Write the encoding target from the given u32 to the given Writer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.