Expand description
Enumerate all possible values of a type.
Enumerable
is a trait used for enumerating all possible values of a type. Calling the enumerator
method of a Enumerable
type will return an iterator that yields all possible values of that type.
use enumerable::Enumerable;
// The output will be:
// 0
// 1
// ...
// 255
for value in u8::enumerator() {
println!("{}", value);
}
Enumerable
is implemented for most primitive types and some standard library types. You can also derive Enumerable
for your own types by #[derive(Enumerable)]
.
use enumerable::Enumerable;
#[derive(Debug, Copy, Clone, Enumerable)]
enum Food {
Apple,
Banana,
Coffee { with_milk: bool },
}
// The output will be:
// None
// Some(Apple)
// Some(Banana)
// Some(Coffee { with_milk: false })
// Some(Coffee { with_milk: true })
for value in <Option<Food> as Enumerable>::enumerator() {
println!("{:?}", value);
}
See the examples for more examples and a guide on how to use this crate.
See the documentation of Enumerable
for more details.
Structs§
- Option
Enumerator OptionEnumerator
is an iterator over possible values ofOption<T>
. It yieldsNone
first, then yieldsSome(item)
for each possible value ofT
.
Traits§
- Enumerable
Enumerable
is a trait for types that can have their possible values enumerated.
Derive Macros§
- Enumerable
- Derives the
Enumerable
trait for an enum or struct.