I'm wondering is there is a way to statically initialize / declare a std::mem::Discriminant? And then is there a way to use that value as an arm of a match statement?
As I understand Discriminants, they can be used to compare two enums that have data without comparing the data. e.g.
if std::mem::discriminant(my_enum_1) == std::mem::discriminant(my_enum_2)
But, I want to create a function that takes a std::mem::Discriminant<> as an argument, and then does a match on the enum type within the function body.
I can't pass a reference to the enum itself into the function, because I don't want to borrow it. I also don't want to clone the first enum for performance reasons. The data in the enum is quite large.
I realize, I could create a work-around, that avoids the use of Discriminant<> altogether, by creating a second enum, which has all of the same possible values as the first enum, but no associated data. Then I could match on the first enum (with associated data) and create an instance of the second enum (without data), and then pass that second enum, and match on it inside the function. But that's a lot of typing for something it feels like the language should just have.
Am I missing something, or is there a better Rust pattern I should be using here?
Thank you in advance.