How can I initialize an integer array [i32; 100] with the default value of i32 (0) by deriving the Default trait? I wrote this code:
#[derive(Default)]
struct A {
a: i32,
arr: [i32; 100],
}
But the compiler rejects it with this error:
error[E0277]: the trait bound `[i32; 100]: Default` is not satisfied
--> src/main.rs:4:5
|
1 | #[derive(Default)]
| ------- in this derive macro expansion
...
4 | arr: [i32; 100],
| ^^^^^^^^^^^^^^^ the trait `Default` is not implemented for `[i32; 100]`
|
= help: the following other types implement trait `Default`:
[T; 0]
[T; 1]
[T; 2]
[T; 3]
[T; 4]
[T; 5]
[T; 6]
[T; 7]
and 27 others
= note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info)