< 返回版块

fifc 发表于 2020-01-02 13:03

// 代码 const MAX:usize = 10; struct Node { value: u64, child: [Option<Box>; MAX] }

static mut ROOT: [Option<Box>; MAX] = [None; MAX];

fn main() { }

// 编译报错,这个Copy trait死活搞不定了 error[E0277]: the trait bound std::option::Option<std::boxed::Box<Node>>: std::marker::Copy is not satisfied --> src\main.rs:8:45 | 8 | static mut ROOT: [Option<Box>; MAX] = [None; MAX]; | ^^^^^^^^^^^ the trait std::marker::Copy is not implemented for std::option::Option<std::boxed::Box<Node>> | = help: the following implementations were found: <std::option::Option as std::marker::Copy> = note: the Copy trait is required because the repeated element will be copied = note: this array initializer can be evaluated at compile-time, for more information, see issue https://github.com/rust-lang/rust/issues/49147

error: aborting due to previous error

For more information about this error, try rustc --explain E0277.

评论区

写评论
xjkdev 2020-01-02 13:37

static mut ROOT: [Option; MAX] = [None, None, None, None, None, None, None, None, None, None];

或者

static mut ROOT: [Option; MAX] = Default::default();

1 共 1 条评论, 1 页