Trait fmap::FunctorSelf
source · pub trait FunctorSelf<'a, A>where
Self: Functor<'a, A, Inner = A, Mapped = Self>,
A: 'a,{ }
Expand description
A Functor
that can be mapped to itself
This trait should be required as bound when the compiler shall infer that
the return type of Functor::fmap
is Self
.
Examples
fn double_inner_i32<'a, T>(outer: T) -> T
where
//T: Functor<'a, i32, Inner = i32>, // doesn't work
T: FunctorSelf<'a, i32>, // use this instead
{
outer.fmap(|x| 2 * x)
// NOTE: The following may be more efficient:
// outer.fmap_fn_mutref(|x| *x *= 2)
}