pub fn in_parallel<I, S, O, R>(
input: impl Iterator<Item = I> + Send,
thread_limit: Option<usize>,
new_thread_state: impl FnOnce(usize) -> S + Send + Clone,
consume: impl FnMut(I, &mut S) -> O + Send + Clone,
reducer: R,
) -> Result<<R as Reduce>::Output, <R as Reduce>::Error>
Available on crate feature
parallel
only.Expand description
Read items from input
and consume
them in multiple threads,
whose output output is collected by a reducer
. Its task is to
aggregate these outputs into the final result returned by this function with the benefit of not having to be thread-safe.
- if
thread_limit
isSome
, the given amount of threads will be used. IfNone
, all logical cores will be used. new_thread_state(thread_number) -> State
produces thread-local state once per thread to be based toconsume
consume(Item, &mut State) -> Output
produces an output given an input obtained byinput
along with mutable state initially created bynew_thread_state(…)
.- For
reducer
, see theReduce
trait