Crate const_size_flatten

Source
Expand description

Versions of FlatMap and Flatten that know their inner iterators’ size in advance. Note that core & std already provide this functionality for some types through a hack using specialization. This crate’s contribution is that the trait ConstSizeIntoIterator is public and the functionality is therefore extensible.

To use, just use const_size_flatten::IteratorExtension.

Structs§

ConstSizeFlatMap
A version of FlatMap that knows its inner iterators’ size in advance, and can produce accurate lower and upper bounds using Iterator::size_hint. This iterator does not require ExactSizeIterator for the inner iterators. It can nonetheless provide an accurate length via Iterator::size_hint if they implement it. This iterator does not implement ExactSizeIterator, even if the inner iterators implement it. This is because the nesting may cause the size to exceed usize::MAX.
ConstSizeFlatten
A version of Flatten that knows its inner iterators’ size in advance, and can produce accurate lower and upper bounds using Iterator::size_hint. This iterator does not require ExactSizeIterator for the inner iterators. It can nonetheless provide an accurate length via Iterator::size_hint if they implement it. This iterator does not implement ExactSizeIterator, even if the inner iterators implement it. This is because the nesting may cause the size to exceed usize::MAX.

Traits§

ConstSizeIntoIterator
Implementors of this trait promise that all iterators they produce always produce the same number of elements. This number is given by the associated constant SIZE. Note that this trait should not be implemented for Iterators, since they can be iterated through, which changes the amount of elements they produce.
IteratorExtension
Convenience trait that allows you to construct ConstSizeFlatten and ConstSizeFlatMap. This trait is sealed, you cannot implement it.

Functions§

const_size_flat_map
Construct a ConstSizeFlatMap from an IntoIterator (which includes Iterators).
const_size_flatten
Construct a ConstSizeFlatten from an IntoIterator (which includes Iterators).