pub fn each_const<const N: usize, F>(f: F)
Expand description
Shorthand for gen_const().for_each(f)
.
See gen_const()
for more information.
See each()
for the non-const generic variant.
ยงExample
See crate root for more examples.
each_const(|[a]| {
println!("{a}");
});
// Outputs:
// false
// true
each_const(|[a, b]| {
println!("{a} {b}");
});
// Outputs:
// false false
// true false
// false true
// true true
each_const(|[a, b, c, d]| {
println!("{a} {b} {c} {d}");
});
// Outputs:
// false false false false
// true false false false
// false true false false
// true true false false
// false false true false
// true false true false
// false true true false
// true true true false
// false false false true
// true false false true
// false true false true
// true true false true
// false false true true
// true false true true
// false true true true
// true true true true
Examples found in repository?
examples/example.rs (lines 39-42)
38fn main() {
39 truth_values::each_const(|[a, b]| {
40 assert_eq!(!(a || b), !a && !b);
41 assert_eq!(!(a && b), !a || !b);
42 });
43
44 let mut exprs = Vec::new();
45 exprs.extend(truth_values::gen_const().map(|[a, b]| {
46 let x = not(or(a, b));
47 let y = and(not(a), not(b));
48 (x, y)
49 }));
50 exprs.extend(truth_values::gen_const().map(|[a, b]| {
51 let x = not(and(a, b));
52 let y = or(not(a), not(b));
53 (x, y)
54 }));
55
56 for (x, y) in exprs {
57 println!("{} = {:?}", x.eval(), x);
58 println!("{} = {:?}", y.eval(), y);
59 println!();
60
61 assert_eq!(x.eval(), y.eval());
62 }
63}