While this is a trivial example, I have multiple generic functions which need to work across a few dozen possible values. The actual value is not known until runtime, as it is provided as an argument.
#![feature(generic_const_exprs)]
fn generic_division<const DIVISOR: u64>(denominator: u64) -> u64 {
denominator / DIVISOR
}
fn main() {
let denominator = 12;
for i in 1..5 {
let dividend = match i {
1 => generic_division::<1>(denominator),
2 => generic_division::<2>(denominator),
3 => generic_division::<3>(denominator),
4 => generic_division::<4>(denominator),
_ => panic!()
};
println!("{} / {} == {}", denominator, i, dividend);
}
}
Is there a better way than above? All other approaches have run into const
issues.