Skip to main content

RefLiftFn

Trait RefLiftFn 

Source
pub trait RefLiftFn: CloneFn<Ref> {
    // Required method
    fn ref_new<'a, A: 'a, B: 'a>(
        f: impl 'a + Fn(&A) -> B,
    ) -> <Self as CloneFn<Ref>>::Of<'a, A, B>;
}
Expand description

A trait for constructing Ref-mode cloneable function wrappers from closures.

This mirrors LiftFn but for by-reference closures (Fn(&A) -> B).

Required Methods§

Source

fn ref_new<'a, A: 'a, B: 'a>( f: impl 'a + Fn(&A) -> B, ) -> <Self as CloneFn<Ref>>::Of<'a, A, B>

Creates a new cloneable by-reference function wrapper.

This function wraps the provided closure f (which takes &A) into a cloneable function.

§Type Signature

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

§Type Parameters
  • 'a: The lifetime of the function and its captured data.
  • A: The input type (the closure receives &A).
  • B: The output type of the function.
§Parameters
  • f: The by-reference closure to wrap.
§Returns

The wrapped cloneable by-reference function.

§Examples
use fp_library::{
	brands::*,
	functions::*,
};

let f = ref_lift_fn_new::<RcFnBrand, _, _>(|x: &i32| *x * 2);
assert_eq!(f(&5), 10);

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§

Source§

impl<P: ToDynCloneFn> RefLiftFn for FnBrand<P>

§Type Parameters
  • P: The reference-counted pointer type.