Optimizing layout of nested enums? and the related https://github.com/rust-lang/rfcs/issues/1230 share the same issues, although I don't see this particular suggestion. So far I can only think of "too weird to be really good ideas" suggestions for how to fix this issue. Better ergonomics around anonymous and/or _::Var
enums might make this possible:
enum DayPadding {
Space,
None,
}
enum YearPadding {
Space,
None,
}
enum Specifier {
Day { padding: DayPadding },
Year { padding: YearPadding },
}
fn main() {
dbg!(std::mem::size_of::<Specifier>());
}
[src/main.rs:17] std::mem::size_of::<Specifier>() = 2
Which I guess is kind of a bug, but also a prerequisite for the OP to work ergonomic changes to help.