Trait pareen::Fun

source ·
pub trait Fun {
    type T;
    type V;

    // Required method
    fn eval(&self, t: Self::T) -> Self::V;
}
Expand description

A Fun represents anything that maps from some type T to another type V.

T usually stands for time and V for some value that is parameterized by time.

Implementation details

The only reason that we define this trait instead of just using Fn(T) -> V is so that the library works in stable rust. Having this type allows us to implement e.g. std::ops::Add for Anim<F> where F: Fun. Without this trait, it becomes difficult (impossible?) to provide a name for Add::Output, unless you have the unstable feature type_alias_impl_trait or fn_traits.

In contrast to std::ops::FnOnce, both input and output are associated types of Fun. The main reason is that this makes types smaller for the user of the library. I have not observed any downsides to this yet.

Required Associated Types§

source

type T

The function’s input type. Usually time.

source

type V

The function’s output type.

Required Methods§

source

fn eval(&self, t: Self::T) -> Self::V

Evaluate the function at time t.

Trait Implementations§

source§

impl<'a, T, V> Fun for Box<dyn Fun<T = T, V = V>>

§

type T = T

The function’s input type. Usually time.
§

type V = V

The function’s output type.
source§

fn eval(&self, t: Self::T) -> Self::V

Evaluate the function at time t.

Implementations on Foreign Types§

source§

impl<F> Fun for Option<F>where F: Fun,

§

type T = <F as Fun>::T

§

type V = Option<<F as Fun>::V>

source§

fn eval(&self, t: F::T) -> Option<F::V>

source§

impl<'a, T, V> Fun for Box<dyn Fun<T = T, V = V>>

§

type T = T

§

type V = V

source§

fn eval(&self, t: Self::T) -> Self::V

source§

impl<'a, F> Fun for &'a Fwhere F: Fun,

§

type T = <F as Fun>::T

§

type V = <F as Fun>::V

source§

fn eval(&self, t: Self::T) -> Self::V

Implementors§

source§

impl<V> Fun for Line<V>where V: Add<Output = V> + Mul<Output = V> + Clone,

§

type T = V

§

type V = V