What is the recommended way to declare a structure containing an array and then create a zero initialized instance?
Here is the structure:
use std::default::Default; use std::num;
and compiler error:
src/lib.rs:17:5: 17:23 error: the trait `core::default::Default` is not implemented for the type `[u32, ..256]` src/lib.rs:17 bins: [u32, ..256], ^~~~~~~~~~~~~~~~~~ note: in expansion of #[deriving] src/lib.rs:14:1: 14:21 note: expansion site src/lib.rs:17:5: 17:23 note: the trait `core::default::Default` must be implemented because it is required by `core::default::Default::default` src/lib.rs:17 bins: [u32, ..256], ^~~~~~~~~~~~~~~~~~ note: in expansion of #[deriving] src/lib.rs:14:1: 14:21 note: expansion site error: aborting due to previous error
If I try to add a missing initializer for the uint8 array:
impl Default for [u32,..256] { fn default () -> [u32,..255]{ [0u8,..256] } }
I get:
src/lib.rs:20:1: 24:2 error: cannot provide an extension implementation where both trait and type are not defined in this crate [E0117] src/lib.rs:20 impl Default for [u32,..256] { src/lib.rs:21 fn default () -> [u32,..255]{ src/lib.rs:22 [0u8,..256] src/lib.rs:23 } src/lib.rs:24 }
Am I doing something wrong or will I be bitten by a beating in the standard library for numeric types on the road to 1.0?
$ rustc --version rustc 0.13.0-nightly
source share