What would be the idiomatic way to write an array that grows automatically (at compile time) when I add an item to an enum?
In C I do this:
typedef enum {
A,
B,
C,
FOO_COUNT,
} foo_t;
int my_array[FOO_COUNT];
This allows me to write code like this, that continues to work just fine when I add a D item before FOO_COUNT in my enum definition.
void foo_init() {
for (int i = 0; i < FOO_COUNT; i++) {
my_array[i] = i;
}
}
What's the idiomatic way to write this in Rust?I know you can literally translate this in Rust (playground), but I would hardly consider that "idiomatic".