You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Need some way to retrieve expected enum discriminant for comparison #4017
There's currently no way to retrieve and store std::mem::Discriminant without explicitly construct an enum value first. However preparing such an enum value might be nontrivial or even have side effects.
I propose for variants defined as constructors (with parenthesis), we could support retrieving the discriminant somehow, directly.
Strawman proposal:
Add a macro called constructor_discriminant (or some better name).
Make this piece of code usable:
enumOutputType{StdOut(std::io::StdOut),StdErr(std::io::StdErr),}let v = OutputType::StdOut(std::io::stdout());assert_eq!(std::mem::discriminant(v), constructor_discriminant!(OutputType::StdOut));
Activity
kennytm commentedon Oct 11, 2026
This is basically the
discriminant_of!macro proposed in #3727.