enumflags
enumflags copied to clipboard
Support for const variants
Is possible to implement support for const variants?
Could you explain what you mean by const?
Something like this?
const FOO: u8 = 0b0100;
#[derive(EnumFlags, Copy, Clone, Debug)]
#[repr(u8)]
pub enum Test {
A = 0b0001,
B = 0b0010,
C = FOO,
D = 0b1000,
}
Yes
This should be possible, unless syn doesn't expose this in ConstExpr.
I am not quite sure if that is currently possible. I don't see a way to access the value of a const var. https://dtolnay.github.io/syn/syn/struct.PathSegment.html
Alternatively I could implement another derive that wouldn't do any safety checks, then I don't need to inspect the value and therefore const values could be supported.