[][src]Macro pareen::anim_match

macro_rules! anim_match {
    (
        $expr:expr;
        $($pat:pat => $value:expr $(,)?)*
    ) => { ... };
}

Build an animation that depends on matching some expression.

Importantly, this macro allows returning animations of a different type in each match arm, which is not possible with a normal match expression.

Example

enum MyPlayerState {
    Standing,
    Running,
    Jumping,
}

fn my_anim(state: MyPlayerState) -> pareen::Anim<impl pareen::Fun<T = f64, V = f64>> {
    pareen::anim_match!(state;
        MyPlayerState::Standing => pareen::constant(0.0),
        MyPlayerState::Running => pareen::prop(1.0),
        MyPlayerState::Jumping => pareen::id().powi(2),
    )
}

assert_approx_eq!(my_anim(MyPlayerState::Standing).eval(2.0), 0.0);
assert_approx_eq!(my_anim(MyPlayerState::Running).eval(2.0), 2.0);
assert_approx_eq!(my_anim(MyPlayerState::Jumping).eval(2.0), 4.0);