I have encountered the want several times recently where in an enum with only struct-like variants all but a few fields are shared both in name and in type between the variants.
Example:
pub enum Foo {
Var1 {
wealth: i32,
likeable: bool,
age: i16
},
Var2 {
wealth: i32,
likeable: bool
}
}
It would be vary nice, both from a readability standpoint and a DRY standpoint if it were possible to do the following (or something like it):
pub enum Foo {
Var1 {
likeable: bool
},
Var2,
{ // blank block
wealth: i32,
likeable: bool
}
}
The two examples would have the same fields. As for errors this would not be allowed if some of the variants were tuple-like. As for implementation, I am not that well versed in how it is handled currently but to make it the most similar in each case I would say that the best place to put them is that the top of every variant.