Boxes and arrays are copyable, so why does this not compile?
#[derive(Debug, Copy, Clone)]
enum Octree{
Branch(Box<[Octree; 8]>),
Filled,
Empty,
}
Compile error:
main.rs:3:17: 3:21 error: the trait `Copy` may not be implemented for this type; variant `Branch` does not implement `Copy` [E0205]
EDIT: Ok, so I don't want Octree to be copyable after all. But how do I make it mutable? I want to be able to change children of a node.
Copy is only for types that are trivially copyable. Box is not Copy because merely copying the pointer would violate the single ownership principle.
You want to use Clone and its clone method here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With