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);
}tasks and rayon only.Expand description
Extension trait for IndexedParallelIterator
that streams results to a sequential consumer in index order.
Required Methods§
Sourcefn for_each_ordered<F>(self, f: F)
fn for_each_ordered<F>(self, f: F)
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.
Sourcefn for_each_ordered_in<F>(self, pool: &ThreadPool, f: F)
fn for_each_ordered_in<F>(self, pool: &ThreadPool, f: F)
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.