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
I was looking for a way to compactly represent a set of enums in a project, and for a second i thought this crate was exactly what i needed, but then i realized that the enum T must have a bitflag-like representation. this is a problem, since i'm already using my enum as an array index, so all its values need to be contiguous.
extracting the index of a bit from a set of bitflags is nontrivial, however making a bitflag from an index is just a single left shift.
i propose a new form, #[bitflags(index)], that gives the enums values linearly (same as the default rust behavior for unit enums).
in order to not confuse other crates that assume impl BitFlag for T means they can cast an enum to an integer in order to get the bitflag value, this would derive a different trait, BitFlagIndex, for the enum. BitFlagIndex would function mostly the same as BitFlag, but with an implicit shift when converting to BitFlags<T> where T: BitFlagIndex.
this would take a moderate effort, but i'm willing to write up a PR if there's a decent chance it'll get merged.
The text was updated successfully, but these errors were encountered:
I was looking for a way to compactly represent a set of enums in a project, and for a second i thought this crate was exactly what i needed, but then i realized that the enum
T
must have a bitflag-like representation. this is a problem, since i'm already using my enum as an array index, so all its values need to be contiguous.extracting the index of a bit from a set of bitflags is nontrivial, however making a bitflag from an index is just a single left shift.
i propose a new form,
#[bitflags(index)]
, that gives the enums values linearly (same as the default rust behavior for unit enums).in order to not confuse other crates that assume
impl BitFlag for T
means they can cast an enum to an integer in order to get the bitflag value, this would derive a different trait, BitFlagIndex, for the enum. BitFlagIndex would function mostly the same as BitFlag, but with an implicit shift when converting toBitFlags<T> where T: BitFlagIndex
.this would take a moderate effort, but i'm willing to write up a PR if there's a decent chance it'll get merged.
The text was updated successfully, but these errors were encountered: