Skip to main content

ParRefFunctor

Trait ParRefFunctor 

Source
pub trait ParRefFunctor: RefFunctor + Kind_cdc7cd43dac7585f {
    // Required method
    fn par_ref_map<'a, A: Send + Sync + 'a, B: Send + 'a>(
        f: impl Fn(&A) -> B + Send + Sync + 'a,
        fa: &Self::Of<'a, A>,
    ) -> Self::Of<'a, B>;
}
Expand description

Parallel by-reference functor mapping.

Maps a Send + Sync function over a structure by reference, potentially using rayon for parallel execution. The closure receives &A instead of consuming A.

Elements must be Send + Sync because rayon’s par_iter() requires &A: Send, which is equivalent to A: Sync.

Required Methods§

Source

fn par_ref_map<'a, A: Send + Sync + 'a, B: Send + 'a>( f: impl Fn(&A) -> B + Send + Sync + 'a, fa: &Self::Of<'a, A>, ) -> Self::Of<'a, B>

Maps a function over the structure by reference in parallel.

§Type Signature

forall A B. (&A -> B, &Self A) -> Self B

§Type Parameters
  • 'a: The lifetime of the elements.
  • A: The input element type.
  • B: The output element type.
§Parameters
  • f: The function to apply to each element reference. Must be Send + Sync.
  • fa: The structure to map over.
§Returns

A new structure containing the mapped elements.

§Examples
use fp_library::{
	brands::VecBrand,
	classes::par_ref_functor::ParRefFunctor,
};

let v = vec![1, 2, 3];
let result = VecBrand::par_ref_map(|x: &i32| x * 2, &v);
assert_eq!(result, vec![2, 4, 6]);

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§