pub unsafe trait GenericThreadPool {
// Required methods
fn upper_bounded_pipeline<Output: Send, Accum>(
self,
input_len: usize,
init: impl Fn() -> Accum + Sync,
process_item: impl Fn(Accum, usize) -> ControlFlow<Accum, Accum> + Sync,
finalize: impl Fn(Accum) -> Output + Sync,
reduce: impl Fn(Output, Output) -> Output,
cleanup: &(impl SourceCleanup + Sync),
) -> Output;
fn iter_pipeline<Output, Accum: Send>(
self,
input_len: usize,
accum: impl Accumulator<usize, Accum> + Sync,
reduce: impl ExactSizeAccumulator<Accum, Output>,
cleanup: &(impl SourceCleanup + Sync),
) -> Output;
}Expand description
A thread pool backend that can execute parallel iterators.
You most likely won’t have to interact with this trait directly, as it is
implemented for &mut ThreadPool, and
interacting with a thread pool is done via the
with_thread_pool() iterator
adaptor. You can implement this trait if you want to use Paralight iterators
with an alternate thread pool implementation that you provide.
§Safety
This trait is marked as unsafe, because implementers must ensure the
safety guarantees of
upper_bounded_pipeline() and
iter_pipeline().
Required Methods§
Sourcefn upper_bounded_pipeline<Output: Send, Accum>(
self,
input_len: usize,
init: impl Fn() -> Accum + Sync,
process_item: impl Fn(Accum, usize) -> ControlFlow<Accum, Accum> + Sync,
finalize: impl Fn(Accum) -> Output + Sync,
reduce: impl Fn(Output, Output) -> Output,
cleanup: &(impl SourceCleanup + Sync),
) -> Output
fn upper_bounded_pipeline<Output: Send, Accum>( self, input_len: usize, init: impl Fn() -> Accum + Sync, process_item: impl Fn(Accum, usize) -> ControlFlow<Accum, Accum> + Sync, finalize: impl Fn(Accum) -> Output + Sync, reduce: impl Fn(Output, Output) -> Output, cleanup: &(impl SourceCleanup + Sync), ) -> Output
Processes an input of the given length in parallel and returns the aggregated output.
With this variant, the pipeline may skip processing items at larger
indices whenever a call to process_item returns
ControlFlow::Break.
§Safety guarantees
This function guarantees that:
- the indices passed to
process_item()are in0..input_len, - the ranges passed to
cleanup.cleanup_item_range()are included in0..input_len, - each index in
0..inner_lenis passed exactly once in calls toprocess_item()andcleanup.cleanup_item_range().
Sourcefn iter_pipeline<Output, Accum: Send>(
self,
input_len: usize,
accum: impl Accumulator<usize, Accum> + Sync,
reduce: impl ExactSizeAccumulator<Accum, Output>,
cleanup: &(impl SourceCleanup + Sync),
) -> Output
fn iter_pipeline<Output, Accum: Send>( self, input_len: usize, accum: impl Accumulator<usize, Accum> + Sync, reduce: impl ExactSizeAccumulator<Accum, Output>, cleanup: &(impl SourceCleanup + Sync), ) -> Output
Processes an input of the given length in parallel and returns the aggregated output.
§Safety guarantees
This function guarantees that:
- the indices passed to
accum.accumulate()are in0..input_len, - the ranges passed to
cleanup.cleanup_item_range()are included in0..input_len, - each index in
0..inner_lenis passed exactly once in calls toaccum.accumulate()andcleanup.cleanup_item_range().
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.
Implementations on Foreign Types§
Source§impl<'a, T> GenericThreadPool for &'a mut Twhere
&'a T: GenericThreadPool,
impl<'a, T> GenericThreadPool for &'a mut Twhere
&'a T: GenericThreadPool,
fn upper_bounded_pipeline<Output: Send, Accum>( self, input_len: usize, init: impl Fn() -> Accum + Sync, process_item: impl Fn(Accum, usize) -> ControlFlow<Accum, Accum> + Sync, finalize: impl Fn(Accum) -> Output + Sync, reduce: impl Fn(Output, Output) -> Output, cleanup: &(impl SourceCleanup + Sync), ) -> Output
fn iter_pipeline<Output, Accum: Send>( self, input_len: usize, accum: impl Accumulator<usize, Accum> + Sync, reduce: impl ExactSizeAccumulator<Accum, Output>, cleanup: &(impl SourceCleanup + Sync), ) -> Output
Implementors§
impl GenericThreadPool for &RayonThreadPool<'_>
rayon and (crate features rayon or default-thread-pool) only.impl GenericThreadPool for &mut ThreadPool
default-thread-pool and (crate features rayon or default-thread-pool) only.