rayon::iter::plumbing

Trait Producer

source
pub trait Producer: Send + Sized {
    type Item;
    type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator + ExactSizeIterator;

    // Required methods
    fn into_iter(self) -> Self::IntoIter;
    fn split_at(self, index: usize) -> (Self, Self);

    // Provided methods
    fn min_len(&self) -> usize { ... }
    fn max_len(&self) -> usize { ... }
    fn fold_with<F>(self, folder: F) -> F
       where F: Folder<Self::Item> { ... }
}
Expand description

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.

Required Associated Types§

source

type Item

The type of item that will be produced by this producer once it is converted into an iterator.

source

type IntoIter: Iterator<Item = Self::Item> + DoubleEndedIterator + ExactSizeIterator

The type of iterator we will become.

Required Methods§

source

fn into_iter(self) -> Self::IntoIter

Convert self into an iterator; at this point, no more parallel splits are possible.

source

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§

source

fn min_len(&self) -> usize

The minimum number of items that we will process sequentially. Defaults to 1, which means that we will split all the way down to a single item. This can be raised higher using the with_min_len method, which will force us to create sequential tasks at a larger granularity. Note that Rayon automatically normally attempts to adjust the size of parallel splits to reduce overhead, so this should not be needed.

source

fn max_len(&self) -> usize

The maximum number of items that we will process sequentially. Defaults to MAX, which means that we can choose not to split at all. This can be lowered using the with_max_len method, which will force us to create more parallel tasks. Note that Rayon automatically normally attempts to adjust the size of parallel splits to reduce overhead, so this should not be needed.

source

fn fold_with<F>(self, folder: F) -> F
where 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.

Object Safety§

This trait is not object safe.

Implementors§