4 ms·
I just wish that Rust’s enum Variants were types… maybe someday! :)
by evntdrvn 4y ago
I just wish that Rust’s enum Variants were types… maybe someday! :)
- epage 4y agoSince I've heard of this idea, I keep finding places where id use it, whether that be for variant-specific behavior or to remove the redudant type definitions in my API.
- zaphar 4y agoIt's not exactly what you want but you get most of the benefit by just wrapping types in enum variants.
- evntdrvn 4y agoThanks yeah, I was just meaning for the ergonomics aspect :) Cheers
- estebank 4y agoIt's a request for the following to be valid enum X { A, B, } fn foo() -> X::A { X::A } which helps a lot when composing state machines. In the meantime, you can indeed do what you propose: enum X { A(Foo), B(Bar), } struct Foo; struct Bar; fn foo() -> Foo { Foo }