Add support for enums where variants are directly bit masks for FFI purposes.
This would also be very useful for wire protocol formats - and relatedly LSB/MSB could also be useful (though probably lower layers of protocol stacks would take care of that concern)
It would be nice to be able to do something like
#[derive(EnumSetType, Debug)]
#[enumset(repr = "u16", serialize_repr = "u16")]
pub enum EventFeatures {
Reserved = 0x08,
EndOfFile = 0x10,
// ...
}
etc.
Right now, such a definition will error with
`repr` is too small to contain the largest discriminant.
`repr` is too small to contain the largest discriminant.
even though u8, let alone u16, should fit for both in-memory and serde serialisation.
The benefit of this is that other code which isn't operating off of the set - e.g. something detecting end of file could directly use the discriminant:
flags = EventFeatures::EndOfFile as u16;
rather than today:
flags = enum_set! {EventFeatures::EndOfFile}.as_repr();
This has been implemented in main via the #[enumset(map = "mask")] attribute. Also added #[enumset(map = "msb")] since it's fairly easy with the same code.