I want to initialize an array of Option<Foo> with [None; 5]. The None variant is constant and has no associated data, so there seems to be no reason that it couldn't be copied into all the entries in the array:
struct Foo;
fn main() {
let mut array: [Option<Foo>; 5] = [None; 5];
}
Sadly this errors because Foo is not Copy, so Option<Foo> is not Copy.
<anon>:4:35: 4:44 error: the trait `core::marker::Copy` is not implemented for the type `Foo` [E0277]
<anon>:4 let array: [Option<Foo>; 5] = [None; 5];
^~~~~~~~~
I gather array initialization treats None as an expression in this case? Could it instead notice that None is a constant, and copy it to all the elements in the array?
I want to initialize an array of
Option<Foo>with[None; 5]. TheNonevariant is constant and has no associated data, so there seems to be no reason that it couldn't be copied into all the entries in the array:Sadly this errors because
Foois notCopy, soOption<Foo>is notCopy.I gather array initialization treats
Noneas an expression in this case? Could it instead notice thatNoneis a constant, and copy it to all the elements in the array?