我在初始化固定长度数组时遇到问题. 到目前为止,我的尝试都导致了"使用可能未初始化的变量:foo_array"错误:
#[derive(Debug)]
struct Foo { a: u32, b: u32 }
impl Default for Foo {
fn default() -> Foo { Foo{a:1, b:2} }
}
pub fn main() {
let mut foo_array: [Foo; 10];
// Do something here to in-place initialize foo_array?
for f in foo_array.iter() {
println!("{:?}", f);
}
}
Run Code Online (Sandbox Code Playgroud)
error[E0381]: use of possibly uninitialized variable: `foo_array`
--> src/main.rs:13:14
|
13 | for f in foo_array.iter() {
| ^^^^^^^^^ use of possibly uninitialized `foo_array`
Run Code Online (Sandbox Code Playgroud)
我实现了Default …