Is there a better/cleaner way of destructuring rust enums without introducing nested hell of a match calls?
My current approach to destructuring multiple nested enums looks like this:
enum Top {
Middle(Middle)
}
enum Middle {
Bottom(Bottom)
}
enum Bottom {
Value(i32)
}
fn foo () -> Top {
Top::Middle(Middle::Bottom(Bottom::Value(17)))
}
fn main() {
match foo() {
Top::Middle(middle) => match middle {
Middle::Bottom(bottom) => match bottom {
Bottom::Value(value) => println!("Value {}", value)
}
}
}
}
If I increase the number of "layers" between Top and Bottom enums the pattern matching becomes "harder" to maintain.
Is there a "linear" way of handling nested enums without losing all functionality that match provides (e.g. notify when some matches are missing etc.)?
I'm looking for something like this
// cut
fn main() {
match foo() {
Top::Middle(Middle::Bottom(Bottom::Value(value))) => println!("Value {}", value)
}
}