[][src]Trait enumset::EnumSetType

pub unsafe trait EnumSetType: Copy + Eq + EnumSetTypePrivate { }

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 automatically implements Copy, Clone, Eq, and PartialEq on the enum. These are required for the EnumSet to function.

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)]
pub enum Enum {
   A, B, C, D, E, F, G,
}

Deriving a sparse EnumSetType:

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

Deriving an EnumSetType without adding ops:

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

Implementors

Loading content...