I can describe the dimension of this "circular" hexgrid..
.. with only 1 value n
defined at compile time:
const GRID_RADIUS: usize = 3;
Therefore, the number of cells in the grid is also known at compile time, since it is (2n+1)^2-n*(n+1)
(here 37).
However, the following:
const N: usize = 3;
const N_CELLS: usize = ((2 * N + 1) ^ 2) - N * (N + 1);
struct Cell;
struct Grid {
cells: [Cell; N_CELLS],
}
Does not compile:
error: any use of this value will cause an error
--> src/main.rs:2:34
|
2 | const N_CELLS: usize = ((2 * N + 1) ^ 2) - N * (N + 1);
| -----------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| attempt to subtract with overflow
|
= note: `#[deny(const_err)]` on by default
I understand that rustc
worries that subtracting usize
types may result in overflow, but I can guarantee that N_CELLS
will always be positive in this case.
How can I take responsibility for this and have rustc
trust me?