Why isn't the enum containing the mailbox copied?

Boxes and arrays can be copied, so why doesn't this compile?

#[derive(Debug, Copy, Clone)]
enum Octree{
    Branch(Box<[Octree; 8]>),
    Filled,
    Empty,
}

      

Compilation 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 to Octree

be copyable. But how can I make it mutable? I want to be able to modify the children of a node.

+3


source to share


1 answer


Copy is only for types that can be trivially copied. The box is not copied, because simply copying the pointer would violate the single ownership principle.



You want to use Clone and its clone method here.

+6


source







All Articles