I need to store a vector of enum discriminants to compare against:
use std::mem;
enum Thing {
Foo(usize),
Bar(usize, usize),
}
let ds: Vec<mem::Discriminant<Thing>> = vec![/* ??? */];
// ...
let thing: Thing = Foo(1234);
for d in ds.iter() {
if mem::discriminant(thing) == d {
println!("yay");
}
}
In practice, what will happen is a macro will be used to generate this list of discriminants in order to match context in a list of enums.
For example, we might have something that looks like this:
enum Thing {
A(usize),
B(f32),
C(u8, u8, u8),
}
context_rule! {
A(a) B(b) C(c) B(d) : a + b + c < d => C(b * c)
}
Which should generate a vector of the discriminants corresponding to vec![A, B, C, B] to be checked against.