Consider the following two examples:
struct Polynomial<const DEGREE: usize> {
factors: [isize; DEGREE + 1],
}
struct GenericSudoku<const SIZE: usize> {
board: [[Option<usize>; SIZE.pow(2)]; SIZE.pow(2)],
}
These don't compile because of arithmetic operations on const generics (as decribed here).
It would however, be very convenient to have const generics that are derived from, but not equal to, other const generics.
Is there some other way to achieve this?
You can do it on nightly, with
#![feature(generic_const_exprs)]
, or if you feel brave, withtypenum
andgeneric-array
:As you can see, it can get very unwieldy quickly.