This may well have been done before, though I couldn't find anything. Basically, add a BoxedClone
trait of the form
trait BoxedClone {
fn box_clone(&self) -> Box<Self>;
}
It can be auto implemented, though we should get specialization sorted first
impl<T: Clone> BoxedClone for T {
fn box_clone(&self) -> Box<Self> {
box self.clone()
}
}
The reason we need this trait is for trait objects. Currently, a trait that extends Clone
isn't object-safe, because there's no way to return Self
directly. Thus, many people use this trait anyway.
Actually, alternatively, this could just be a default method on Clone
itself. Thus we don't need to wait for specialization, and it makes sense to be here.