Trait rayon::iter::plumbing::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§

source§

impl Producer for rayon::range::IterProducer<i8>

§

type Item = <Range<i8> as Iterator>::Item

§

type IntoIter = Range<i8>

source§

impl Producer for rayon::range::IterProducer<i16>

source§

impl Producer for rayon::range::IterProducer<i32>

source§

impl Producer for rayon::range::IterProducer<isize>

source§

impl Producer for rayon::range::IterProducer<u8>

§

type Item = <Range<u8> as Iterator>::Item

§

type IntoIter = Range<u8>

source§

impl Producer for rayon::range::IterProducer<u16>

source§

impl Producer for rayon::range::IterProducer<u32>

source§

impl Producer for rayon::range::IterProducer<usize>

source§

impl<'a, P> Producer for PanicFuseProducer<'a, P>
where P: Producer,

§

type Item = <P as Producer>::Item

§

type IntoIter = PanicFuseIter<'a, <P as Producer>::IntoIter>

source§

impl<'a, T, P> Producer for ClonedProducer<P>
where P: Producer<Item = &'a T>, T: 'a + Clone,

§

type Item = T

§

type IntoIter = Cloned<<P as Producer>::IntoIter>

source§

impl<'a, T, P> Producer for CopiedProducer<P>
where P: Producer<Item = &'a T>, T: 'a + Copy,

§

type Item = T

§

type IntoIter = Copied<<P as Producer>::IntoIter>

source§

impl<'data, T: 'data + Send> Producer for ChunksExactMutProducer<'data, T>

§

type Item = &'data mut [T]

§

type IntoIter = ChunksExactMut<'data, T>

source§

impl<'data, T: 'data + Send> Producer for ChunksMutProducer<'data, T>

§

type Item = &'data mut [T]

§

type IntoIter = ChunksMut<'data, T>

source§

impl<'data, T: 'data + Send> Producer for RChunksExactMutProducer<'data, T>

§

type Item = &'data mut [T]

§

type IntoIter = RChunksExactMut<'data, T>

source§

impl<'data, T: 'data + Send> Producer for RChunksMutProducer<'data, T>

§

type Item = &'data mut [T]

§

type IntoIter = RChunksMut<'data, T>

source§

impl<'data, T: 'data + Send> Producer for IterMutProducer<'data, T>

§

type Item = &'data mut T

§

type IntoIter = IterMut<'data, T>

source§

impl<'data, T: 'data + Send> Producer for DrainProducer<'data, T>

§

type Item = T

§

type IntoIter = SliceDrain<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for ChunksExactProducer<'data, T>

§

type Item = &'data [T]

§

type IntoIter = ChunksExact<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for ChunksProducer<'data, T>

§

type Item = &'data [T]

§

type IntoIter = Chunks<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for RChunksExactProducer<'data, T>

§

type Item = &'data [T]

§

type IntoIter = RChunksExact<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for RChunksProducer<'data, T>

§

type Item = &'data [T]

§

type IntoIter = RChunks<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for rayon::slice::IterProducer<'data, T>

§

type Item = &'data T

§

type IntoIter = Iter<'data, T>

source§

impl<'data, T: 'data + Sync> Producer for WindowsProducer<'data, T>

§

type Item = &'data [T]

§

type IntoIter = Windows<'data, T>

source§

impl<'f, P, F> Producer for InspectProducer<'f, P, F>
where P: Producer, F: Fn(&P::Item) + Sync,

§

type Item = <P as Producer>::Item

§

type IntoIter = Inspect<<P as Producer>::IntoIter, &'f F>

source§

impl<'f, P, F> Producer for UpdateProducer<'f, P, F>
where P: Producer, F: Fn(&mut P::Item) + Send + Sync,

source§

impl<'f, P, F, R> Producer for MapProducer<'f, P, F>
where P: Producer, F: Fn(P::Item) -> R + Sync, R: Send,

§

type Item = <F as FnOnce(<P as Producer>::Item)>::Output

§

type IntoIter = Map<<P as Producer>::IntoIter, &'f F>

source§

impl<'f, P, INIT, U, F, R> Producer for MapInitProducer<'f, P, INIT, F>
where P: Producer, INIT: Fn() -> U + Sync, F: Fn(&mut U, P::Item) -> R + Sync, R: Send,

§

type Item = R

§

type IntoIter = MapWithIter<'f, <P as Producer>::IntoIter, U, F>

source§

impl<'f, P, U, F, R> Producer for MapWithProducer<'f, P, U, F>
where P: Producer, U: Send + Clone, F: Fn(&mut U, P::Item) -> R + Sync, R: Send,

§

type Item = R

§

type IntoIter = MapWithIter<'f, <P as Producer>::IntoIter, U, F>

source§

impl<A, B> Producer for ChainProducer<A, B>
where A: Producer, B: Producer<Item = A::Item>,

§

type Item = <A as Producer>::Item

§

type IntoIter = ChainSeq<<A as Producer>::IntoIter, <B as Producer>::IntoIter>

source§

impl<A: Producer, B: Producer> Producer for ZipProducer<A, B>

§

type Item = (<A as Producer>::Item, <B as Producer>::Item)

§

type IntoIter = Zip<<A as Producer>::IntoIter, <B as Producer>::IntoIter>

source§

impl<I, J> Producer for InterleaveProducer<I, J>
where I: Producer, J: Producer<Item = I::Item>,

source§

impl<P> Producer for EnumerateProducer<P>
where P: Producer,

§

type Item = (usize, <P as Producer>::Item)

§

type IntoIter = Zip<Range<usize>, <P as Producer>::IntoIter>

source§

impl<P> Producer for IntersperseProducer<P>
where P: Producer, P::Item: Clone + Send,

source§

impl<P> Producer for MaxLenProducer<P>
where P: Producer,

§

type Item = <P as Producer>::Item

§

type IntoIter = <P as Producer>::IntoIter

source§

impl<P> Producer for MinLenProducer<P>
where P: Producer,

§

type Item = <P as Producer>::Item

§

type IntoIter = <P as Producer>::IntoIter

source§

impl<P> Producer for RevProducer<P>
where P: Producer,

§

type Item = <P as Producer>::Item

§

type IntoIter = Rev<<P as Producer>::IntoIter>

source§

impl<P> Producer for StepByProducer<P>
where P: Producer,

§

type Item = <P as Producer>::Item

§

type IntoIter = StepBy<<P as Producer>::IntoIter>

source§

impl<P, F, T> Producer for ChunkProducer<P, F>
where P: Producer, F: Fn(P::IntoIter) -> T + Send + Clone,

§

type Item = T

§

type IntoIter = Map<ChunkSeq<P>, F>

source§

impl<T: Clone + Send> Producer for RepeatNProducer<T>

§

type Item = T

§

type IntoIter = Iter<T>

source§

impl<T: Send> Producer for OptionProducer<T>

§

type Item = T

§

type IntoIter = IntoIter<T>

source§

impl<T: Send> Producer for EmptyProducer<T>

§

type Item = T

§

type IntoIter = Empty<T>