Skip to main content

ForEachOrdered

Trait ForEachOrdered 

Source
pub trait ForEachOrdered: IndexedParallelIterator {
    // Required methods
    fn for_each_ordered<F>(self, f: F)
       where Self::Item: Send,
             F: FnMut(Self::Item);
    fn for_each_ordered_in<F>(self, pool: &ThreadPool, f: F)
       where Self::Item: Send,
             F: FnMut(Self::Item);
}
Available on crate feature rayon only.
Expand description

Extension trait for [IndexedParallelIterator] that streams results to a sequential consumer in index order.

Required Methods§

Source

fn for_each_ordered<F>(self, f: F)
where Self::Item: Send, F: FnMut(Self::Item),

Executes the parallel iterator, calling f on each result sequentially in index order.

Items are computed in parallel, but f is invoked as f(item_0), f(item_1), …, f(item_{n-1}) on the calling thread. The calling thread receives each item as soon as it (and all preceding items) are ready.

f does not need to be Send — it runs exclusively on the calling thread.

§Blocking

The calling thread blocks (via [Condvar]) while waiting for the next item to become ready. It does not participate in rayon’s work-stealing while blocked. Callers should invoke this from a dedicated blocking thread (e.g. via [tokio::task::spawn_blocking]) rather than from within the rayon thread pool.

Source

fn for_each_ordered_in<F>(self, pool: &ThreadPool, f: F)
where Self::Item: Send, F: FnMut(Self::Item),

Like for_each_ordered, but runs the parallel work on the given pool instead of the global rayon thread pool.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<I> ForEachOrdered for I
where I: IndexedParallelIterator,