Is it possible to create arrays of a technically variable size but that is known at compile time ? More precisely, I want to do something like this :
fn main() {
for n in 1..5 {
let array: [i32; n] = [0; n];
// Do stuff with array
}
}
This code does not compile, but i feel like it should be possible to do, since the only thing the for loop could be unraveled by the compiler, like this :
fn main() {
let array: [i32; 1] = [0; 1];
let array: [i32; 2] = [0; 2];
let array: [i32; 3] = [0; 3];
let array: [i32; 4] = [0; 4];
let array: [i32; 5] = [0; 5];
}
which compiles and does what I want, but is very repetitive
I could use vectors or other data structures, but then I would have variables in the heap, and I don't think that I should use the heap just because i use my arrays in a for loop