Initialize an array with implicit size?

Viewed 29

In Rust, is it always necessary to declare the size of an array, even when it's obvious from the initialization what the size should be?

For example:

let nums: [i32; 3] = [1, 2, 3];

If I decide to edit my code and add [..., 4] to the end of that array, why can't the compiler figure out that nums is now [i32; 4]?

I think what I'm wishing for is something like this (bad notation?):

let nums: [i32] = [1, 2, 3]; // does not compile
0 Answers
Related