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
45
46
47
48
49
50
51
52
use enumerable::Enumerable;
fn main() {
// `Enumerable` is also implemented for other useful types, like tuples.
//
// Tuples with 0 to 16 elements are supported. The built-in implementation will yield all
// possible values of the tuple in a lexicographic order. For example, for a tuple
// `(bool, bool)`, the possible values will be:
//
// - (false, false)
// - (false, true)
// - (true, false)
// - (true, true)
// A tuple with no elements is equivalent to the unit type `()`, with only one possible value.
println!(
"printing all possible values of () ({} in total):",
<()>::ENUMERABLE_SIZE
);
for value in <()>::enumerator() {
println!("{:?}", value);
}
println!();
// A tuple with one element is equivalent to the element itself.
println!(
"printing all possible values of (bool,) ({} in total):",
<(bool,)>::ENUMERABLE_SIZE
);
for value in <(bool,)>::enumerator() {
println!("{:?}", value);
}
println!();
// A tuple with more elements.
println!(
"printing all possible values of (bool, bool, bool) ({} in total):",
<(bool, bool, bool)>::ENUMERABLE_SIZE
);
for value in <(bool, bool, bool)>::enumerator() {
println!("{:?}", value);
}
println!();
// The number of possible values of a tuple is the product of the number of possible values of
// each element. For example, for a tuple `(u16, u16, u16, u16)`, the number of possible values
// will be 2^16 * 2^16 * 2^16 * 2^16 = 2^64, which exceeds `usize::MAX`.
println!(
"does the number of possible (u16, u16, u16, u16) values exceed usize::MAX? {}",
<(u16, u16, u16, u16)>::ENUMERABLE_SIZE_OPTION.is_none()
);
}