Closed
Description
This will lead to a compilation error:
#[bitflags]
#[repr(u64)]
#[derive(Copy, Clone, DeriveEncode, DeriveDecode)]
pub enum EnumWithU64Repr {
/// This item is transferable.
Transferable,
/// The metadata of this item can be modified.
UnlockedMetadata,
/// Attributes of this item can be modified.
UnlockedAttributes,
}
That's because #[bitflags]
does:
pub enum EnumWithU64Repr {
/// This item is transferable.
Transferable = 1,
/// The metadata of this item can be modified.
UnlockedMetadata =
::enumflags2::_internal::next_bit(EnumWithU64Repr::Transferable as u128) as u64,
/// Attributes of this item can be modified.
UnlockedAttributes = ::enumflags2::_internal::next_bit(
EnumWithU64Repr::Transferable as u128 | EnumWithU64Repr::UnlockedMetadata as u128,
) as u64,
}
And this will not work well with the duplicate variant indexes checking logic introduced in #653 and #687
Example of polkadot-sdk structure using #[bitflags]
: ItemSettings
Metadata
Metadata
Assignees
Labels
No labels