To add to @hashedone’s answer, you can use
Box::into_boxed_slice if you’d like to end up with a
Box<[i32]> (note this will be different from a box holding a compile-time fixed size array):
let arr = vec![0; 5_000_000].into_boxed_slice();
This is slightly more efficient than a
Vec<i32> because the capacity field is dropped, and you end up with a fixed size slice.
In case you’re using the nightly compiler, you can use the
box_syntax unstable feature to do what you want:
let arr = box [0; 5_000_000];
In general, arrays whose length is >32 are a lot less ergonomic/useful in current Rust, so you may want to avoid them for those reasons as well.