Trait enumset::EnumSetType
source · [−]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 stable, and may change at any time.
Custom Derive
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.
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.
In addition, if you have renamed the enumset
crate in your crate, you can use the
#[enumset(crate_name = "enumset2")]
attribute to tell the custom derive to use that name
instead.
Attributes controlling the serialization of an EnumSet
are documented in
its documentation.
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,
}