i want to make a 2D fixed size array that is going to be initialized in a for loop. This is the sample code (The Cell struct can not implement Copy or Default trait for some reason):
let mut cells: [[Cell; 20]; 20];
for i in 0..20 {
for j in 0..20 {
cells[i][j] = Cell::new(some_value_based_on_i_and_j);
}
}
but then compiler gives this error:
use of possibly-uninitialized variable
So in order to assure the compiler that my array is fully initialized for at least 1 time; i change it to something like this:
let mut cells: [[Cell; 20]; 20] = [[Cell::new(default_value); 20]; 20];
for i in 0..20 {
for j in 0..20 {
cells[i][j] = Cell::new(some_value_based_on_i_and_j);
}
}
(in fact i want to listen to the compiler and initialize all of the indices of my array with a default value like this pattern and then do my previous job):
let a = [-12, 100] // means -> [default_value, repetition_or_also_length_of_the_array]
Then the compiler gives this error:
the trait bound [maze_maker::Cell; 20]: std::marker::Copy
is not satisfied
the trait std::marker::Copy
is not implemented for [maze_maker::Cell; 20]
note: the Copy
trait is required because the repeated element will be copied
What should i do ): ?