I find myself often defining enum
types like the following:
struct Foo { }
struct Bar { }
struct Baz { }
enum MyEnum {
Foo(Foo),
Bar(Bar),
Baz(Baz),
}
I find the repetition of Foo(Foo)
inelegant and redundant. It also makes initialization redundant:
let example = MyEnum::Foo(Foo{ /* ... */ });
I would like to instead write something like the following pseudocode:
struct Foo { }
struct Bar { }
struct Baz { }
type_enum MyEnum {
Foo,
Bar,
Baz,
}
let example = MyEnum::Foo{ /* ...anything that `Foo` supports ... */ };
The above is very similar to std::variant
in C++17. Does Rust support anything like that?