I have two data structures indexed by T: EnumSetType.
/// A bitset similar to [`BitMatrix`][super::BitMatrix],
/// but with a fixed column and row count, one row per `T` variant.
pub struct EnumBitMatrix<T: EnumSetType>(Box<[u32]>, PhantomData<T>);
/// A MultiMap stored in a [`JaggedArray`].
///
/// The key set need to be bound and exhaustively known at compile time,
/// ie: it must be an enum derived with `#[derive(EnumSetType)]`.
///
/// Use it as follow:
/// `EnumMultiMap<MyEnumSet, String, { (MyEnumSet::BIT_WIDTH - 1) as usize }>`
pub struct EnumMultiMap<K: EnumSetType, V, const CLM: usize>
I use the bit position of T as index in my collection. I also use BIT_WIDTH to size the arrays used in those data structures. It's very pleasant.
However, there is no way to get a bit position outside of EnumSeTypePrivate::enum_into_u32, and no const way of getting the bit width outside of EnumSeTypePrivate::BIT_WIDTH. I don't want to rely on private/unstable API, so I'm opening an issue to request a "stable" way of getting those.
An explicit representation doesn't solve this. The BIT_WIDTH and enum_into_u32 is independent from the representation of T, Ideally I can have as many variants as I want.
I imagine the "bit position" is problematic for enums defined with explicit variant values, so I guess this needs to be part of a new trait only valid for enums without explicit variant values. For example, EnumBitSetType.
What do you think of this? Would you be open to a PR for such a new trait?
The bit position is actually pretty stable, since it's already exposed via e.g. EnumSet::to_u64. I'll think about whether this is viable at this point; it should be.
I have two data structures indexed by
T: EnumSetType
.I use the bit position of
T
as index in my collection. I also useBIT_WIDTH
to size the arrays used in those data structures. It's very pleasant.However, there is no way to get a bit position outside of
EnumSeTypePrivate::enum_into_u32
, and noconst
way of getting the bit width outside ofEnumSeTypePrivate::BIT_WIDTH
. I don't want to rely on private/unstable API, so I'm opening an issue to request a "stable" way of getting those.An explicit representation doesn't solve this. The
BIT_WIDTH
andenum_into_u32
is independent from the representation of T, Ideally I can have as many variants as I want.I imagine the "bit position" is problematic for enums defined with explicit variant values, so I guess this needs to be part of a new trait only valid for enums without explicit variant values. For example,
EnumBitSetType
.What do you think of this? Would you be open to a PR for such a new trait?