Copy trait needed for None?

I'm a newbie, but I think this should work:

let tmpx: Vec<Option> = vec![None; nds.len()];
^^^^^^^^^^^^^^^^^^^^^ the trait std::clone::Clone is not implemented for plan::SomePlan

I want to fill a vector with None, then later fill some slots with unique Some(..) values.

Unfortunately None is not a type of its own, so this has to depend on Option<T> as a whole.

As a workaround, you could do this:

let mut tmpx: Vec<Option<_>> = Vec::new();
tmpx.resize_with(nds.len(), || None);
// or
tmpx.resize_with(nds.len(), Option::default);
1 Like

Thanks!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.