Trait 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)
}

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<'a, T, A> FunctorSelf<'a, A> for T
where T: Functor<'a, A, Inner = A, Mapped = Self>, A: 'a,