Skip to main content

SendRefFunctorWithIndex

Trait SendRefFunctorWithIndex 

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

Thread-safe by-reference mapping with index over a structure.

Similar to RefFunctorWithIndex, but closures and elements must be Send + Sync.

Required Methods§

Source

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

Maps a function over the structure by reference with index (thread-safe).

§Type Signature

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

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

The mapped structure.

§Examples
use fp_library::{
	brands::*,
	classes::send_ref_functor_with_index::SendRefFunctorWithIndex,
	types::*,
};

let lazy = ArcLazy::new(|| 42);
let mapped = <LazyBrand<ArcLazyConfig> as SendRefFunctorWithIndex>::send_ref_map_with_index(
	|_, x: &i32| x.to_string(),
	&lazy,
);
assert_eq!(*mapped.evaluate(), "42");

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§