[−][src]Trait asparit::IndexedProducer
A Producer
is effectively a "splittable IntoIterator
". That
is, a producer is a value which can be converted into an iterator
at any time: at that point, it simply produces items on demand,
like any iterator. But what makes a Producer
special is that,
before we convert to an iterator, we can also split it at a
particular point using the split_at
method. This will yield up
two producers, one producing the items before that point, and one
producing the items after that point (these two producers can then
independently be split further, or be converted into iterators).
In Rayon, this splitting is used to divide between threads.
See the plumbing
README for further details.
Note that each producer will always produce a fixed number of items N. However, this number N is not queryable through the API; the consumer is expected to track it.
NB. You might expect Producer
to extend the IntoIterator
trait. However, rust-lang/rust#20671 prevents us from
declaring the DoubleEndedIterator and ExactSizeIterator
constraints on a required IntoIterator trait, so we inline
IntoIterator here until that issue is fixed.
Associated Types
type Item
The type of item that will be produced by this producer once it is converted into an iterator.
type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator + ExactSizeIterator
The type of iterator we will become.
Required methods
pub fn into_iter(self) -> Self::IntoIter
Convert self
into an iterator; at this point, no more parallel splits
are possible.
pub fn len(&self) -> usize
Produces an exact count of how many items this producer will emit, presuming no panic occurs.
pub fn split_at(self, index: usize) -> (Self, Self)
Split into two producers; one produces items 0..index
, the
other index..N
. Index must be less than or equal to N
.
Provided methods
pub fn fold_with<F>(self, folder: F) -> F where
F: Folder<Self::Item>,
F: Folder<Self::Item>,
Iterate the producer, feeding each element to folder
, and
stop when the folder is full (or all elements have been consumed).
The provided implementation is sufficient for most iterables.