Been running into the issue listed at https://stackoverflow.com/questions/23810032/how-to-specify-const-array-in-global-scope-in-rust.
const NUMBERS: [i32] = [1, 2, 3, 4, 5];
error[E0308]: mismatched types --> src/main.rs:2:28 | 2 | const NUMBERS: [i32] = [1, 2, 3, 4, 5]; | ^^^^^^^^^^^^^^^ expected slice, found array of 5 elements | = note: expected type `[i32]` = note: found type `[i32; 5]` error[E0277]: the trait bound `[i32]: std::marker::Sized` is not satisfied --> src/main.rs:2:28 | 2 | const NUMBERS: [i32] = [1, 2, 3, 4, 5]; | ^^^^^^^^^^^^^^^ the trait `std::marker::Sized` is not implemented for `[i32]` | = note: `[i32]` does not have a constant size known at compile-time = note: constant expressions must have a statically known size error: aborting due to 2 previous errors error: Could not compile `rust-test`.
Is there a way to avoid counting the number of elements without adding a performance penalty as is shown in the answer? http://stackoverflow.com/a/23810557/1398841
Is the reason for this requirement just to keep things explicit and consistent? I could imagine a possible:
const NUMBERS: [i32; ..] = [1, 2, 3, 4, 5];