3 ms·
Right, better control of the index type can help you say what you mean, and help the typechecker catch more mistakes. If I have an array representing a single-
by mjw1007 5y ago
Right, better control of the index type can help you say what you mean, and help the typechecker catch more mistakes.
If I have an array representing a single-byte lookup table, it would be nice if I could say that the array's type is array-indexed-by-u8 rather than array-indexed-by-usize.
Ada did this well: it even lets you declare an array whose index is some enumerated type.
- Ar-Curunir 5y ago> _ it even lets you declare an array whose index is some enumerated type._ You can do this in Rust also: make a custom newtype wrapper for your array, and impl Index<CustomEnum> for the wrapped array.