Perhaps this is a terrible idea, has already been discussed, or is already possible in ways I don’t know, but what if it were possible to implement a trait for all variants of an enum? Something like this:
enum Thing {
A,
B
}
trait Foo {
fn bar() -> usize;
}
impl Foo for Thing::A {
fn bar() -> usize {
1
}
}
impl Foo for Thing::B {
fn bar() -> usize {
2
}
}
I don’t really understand how this is different from impl Foo for Thing. If you’re going to be required to impl Foo for every variant of Thing, why not just impl it on Thing directly? What does this proposal allow you to do that wouldn’t otherwise be possible?