enumflags icon indicating copy to clipboard operation
enumflags copied to clipboard

Support for const variants

Open henninglive opened this issue 8 years ago • 4 comments

Is possible to implement support for const variants?

henninglive avatar Feb 25 '17 16:02 henninglive

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,
}

MaikKlein avatar Feb 27 '17 17:02 MaikKlein

Yes

henninglive avatar Feb 27 '17 18:02 henninglive

This should be possible, unless syn doesn't expose this in ConstExpr.

MaikKlein avatar Feb 27 '17 19:02 MaikKlein

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.

MaikKlein avatar Feb 28 '17 01:02 MaikKlein