Let say I define and instantiate an enum as follows:
enum MyEnum {
EmptyVariant,
TupleVariant(u8),
StructVariant {
key: u8,
value: char,
}
}
let instance = MyEnum::StructVariant{key: 8, value: 'a'};
Is it possible to match against this variant without destructuring? For example, instead of doing:
if let MyEnum::StructVariant{key, value} = instance {
eprintln!("key, value = {}, {}", key, value);
}
I would rather write something like:
if let MyEnum::StructVariant{VARIANT_MEMBERS} = instance {
eprintln!("key, value = {}, {}", VARIANT_MEMBERS.key, VARIANT_MEMBERS.value);
}
In this example, writing out the members of the struct variant is benign, but in the case where the variant has many members it makes the code difficult to read.