boolenum
BoolEnum
is a derive macro to create ergonomic boolean enums with less boilerplate.
It generates From<bool>
, Into<bool>
and Not
impls for your enum.
use BoolEnum;
// Variant names can be Yes and No (in any order) ...
// or True and False
Boolean enums are useful for differentiating between boolean arguments to a function,
so you can write something like encode(&bytes, Encrypt::Yes, Compress::No)
instead of encode(&bytes, true, false)
.
Goes well with structopt, for type-safe handling of command-line flags:
use BoolEnum;
use StructOpt;
BoolEnum
works on enums with two unit variants, named either Yes and No, or True and False. The order of the variants in the enum doesn't matter.
License: MIT OR Apache-2.0