In C++, I could put an array of 1000 int
s onto the heap like this:
int size = 1000;
int* values = new int[size];
delete[] values;
I can't figure out how to do the equivalent in Rust.
let size = 1000;
let values = Box::new([0; size]) // error: non-constant path in constant expression
To my understanding, Rust forces the size of all arrays to be known at compile time and doesn't let you use expressions when creating arrays.