I made a simple struct and implemented Default
for it:
#[derive(Clone, Copy)]
struct LifeCell {
state: usize
}
impl Default for LifeCell {
fn default() -> LifeCell {
LifeCell {
state: 0
}
}
}
I'm trying to create an array of such structs:
const TOTAL_CELLS: usize = 20;
let mut new_field: [[LifeCell; TOTAL_CELLS]; TOTAL_CELLS] = Default::default();
This compiles okay until I set TOTAL_CELLS
to 35. Then it doesn't compile with an error:
error[E0277]: the trait bound `[[LifeCell; 35]; 35]: std::default::Default` is not satisfied
--> src/main.rs:14:65
|
14 | let mut new_field: [[LifeCell; TOTAL_CELLS]; TOTAL_CELLS] = Default::default();
| ^^^^^^^^^^^^^^^^ the trait `std::default::Default` is not implemented for `[[LifeCell; 35]; 35]`
|
= help: the following implementations were found:
<&'a [T] as std::default::Default>
<&'a mut [T] as std::default::Default>
<[T; 32] as std::default::Default>
<[T; 31] as std::default::Default>
and 31 others
= note: required by `std::default::Default::default`
I know the reason for it - at the moment, the Default
trait is implemented only for array sizes up to 32. But what should I do if I need an array of structs that is bigger than that?
I'm using Rust 1.18.0.