static-dispatch 0.3.0

Implement a trait for an enum, where all variants implement the trait
Documentation
#[static_dispatch::setup]
trait FirstBehavior {
    fn first(&self);
}

#[static_dispatch::setup]
trait SecondBehavior {
    fn second(&self);
}

struct A;
impl FirstBehavior for A {
    fn first(&self) {}
}
impl SecondBehavior for A {
    fn second(&self) {}
}

struct B;
impl FirstBehavior for B {
    fn first(&self) {}
}
impl SecondBehavior for B {
    fn second(&self) {}
}

#[static_dispatch::setup]
enum Other {
    A(A),
    B(B),
}

static_dispatch::implementation!(FirstBehavior for Other);
static_dispatch::implementation!(SecondBehavior for Other);

#[test]
fn multiple_traits() {
    let mut other = Other::A(A);
    other.first();
    other.second();
    other = Other::B(B);
    other.first();
    other.second();
}