1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Enumerate all possible values of a type.
[`Enumerable`](trait.Enumerable.html) is a trait used for enumerating all possible values of a type. Calling the [`enumerator`](trait.Enumerable.html#tymethod.enumerator) method of a `Enumerable` type will return an iterator that yields all possible values of that type.
```rust
use enumerable::Enumerable;
// The output will be:
// 0
// 1
// ...
// 255
for value in u8::enumerator() {
}
```
`Enumerable` is implemented for most primitive types and some standard library types. You can also derive `Enumerable` for your own types by `#[derive(Enumerable)]`.
```rust
use enumerable::Enumerable;
enum Food {
}
// 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() {
}
```
See the [examples](https://github.com/GeminiLab/enumerable/tree/main/examples) for more examples and a guide on how to use this crate.
See the documentation of [`Enumerable`](trait.Enumerable.html) for more details.