Skip to main content

GenericThreadPool

Trait GenericThreadPool 

Source
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§

Source

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 in 0..input_len,
  • the ranges passed to cleanup.cleanup_item_range() are included in 0..input_len,
  • each index in 0..inner_len is passed exactly once in calls to process_item() and cleanup.cleanup_item_range().
Source

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 in 0..input_len,
  • the ranges passed to cleanup.cleanup_item_range() are included in 0..input_len,
  • each index in 0..inner_len is passed exactly once in calls to accum.accumulate() and cleanup.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 T

Source§

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

Source§

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§

Source§

impl GenericThreadPool for &RayonThreadPool<'_>

Available on crate feature rayon and (crate features rayon or default-thread-pool) only.
Source§

impl GenericThreadPool for &mut ThreadPool

Available on crate feature default-thread-pool and (crate features rayon or default-thread-pool) only.