Trait enumset::EnumSetType

source ·
pub unsafe trait EnumSetType: Copy { }
Expand description

The trait used to define enum types that may be used with EnumSet.

This trait should be implemented using #[derive(EnumSetType)]. Its internal structure is not currently stable, and may change at any time.

Custom Derive

The custom derive for EnumSetType automatically creates implementations of PartialEq, Sub, BitAnd, BitOr, BitXor, and Not allowing the enum to be used as if it were an EnumSet in expressions. This can be disabled by adding an #[enumset_no_ops] annotation to the enum.

The custom derive for EnumSetType also automatically creates implementations equivalent to #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]. This can be disabled by adding an #[enumset_no_derives] annotation to the enum.

Any C-like enum is supported, as long as there are no more than 128 variants in the enum, and no variant discriminator is larger than 127.

Examples

Deriving a plain EnumSetType:

#[derive(EnumSetType, Debug)]
pub enum Enum {
   A, B, C, D, E, F, G,
}

Deriving a sparse EnumSetType:

#[derive(EnumSetType, Debug)]
pub enum SparseEnum {
   A = 10, B = 20, C = 30, D = 127,
}

Deriving an EnumSetType without adding ops:

#[derive(EnumSetType, Debug)]
#[enumset_no_ops]
pub enum NoOpsEnum {
   A, B, C, D, E, F, G,
}

Implementors