Skip to main content

RefFunctorWithIndex

Trait RefFunctorWithIndex 

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

By-reference mapping with index over a structure.

Similar to FunctorWithIndex, but the closure receives &A instead of A. This is the honest interface for memoized types like Lazy that internally hold a cached &A.

Required Methods§

Source

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

Maps a function over the structure by reference, providing the index.

§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.
  • fa: The structure to map over.
§Returns

The mapped structure.

§Examples
use fp_library::{
	brands::*,
	classes::ref_functor_with_index::RefFunctorWithIndex,
	types::*,
};

let lazy = RcLazy::new(|| 42);
let mapped = <LazyBrand<RcLazyConfig> as RefFunctorWithIndex>::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§