Functor

Trait Functor 

Source
pub trait Functor<F, T>
where F: FnOnce(Self::Elem) -> T,
{ type Cont<U>: ?Sized; type Elem; // Required method fn apply(self, f: F) -> Self::Cont<T>; }
Expand description

The Functor trait describes an interface for a higher-kinded type that can be mapped over. The trait is parameterized over a function F and a target type T, allowing for granular control over the mapping process itself, relying on associated types like Cont<U> to define the resulting container type after the mapping operation and the Elem type to specify the type of elements contained within the functor before the mapping operation is applied. Moreover, the apply method takes ownership of the functor allowing for distinct implementations for referenced, mutabled, and owned instances.

Required Associated Types§

Required Methods§

Source

fn apply(self, f: F) -> Self::Cont<T>

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.

Implementations on Foreign Types§

Source§

impl<'a, U, V, F> Functor<F, V> for &'a Option<U>
where F: FnOnce(&U) -> V,

Source§

type Cont<T> = Option<T>

Source§

type Elem = &'a U

Source§

fn apply(self, f: F) -> <&'a Option<U> as Functor<F, V>>::Cont<V>

Source§

impl<U, V, F> Functor<F, V> for Option<U>
where F: FnOnce(U) -> V,

Source§

type Cont<T> = Option<T>

Source§

type Elem = U

Source§

fn apply(self, f: F) -> <Option<U> as Functor<F, V>>::Cont<V>

Implementors§