I was writing a library for a generic Box<T> and on one part of the code I needed to clone the Box<T>, so I did something like this:
impl<T> OnTheFlySwap<T> where T: ?Sized + Send + Sync, Box<T>: Clone { I added Box<T>: Clone thinking this is not a big deal, because only objects that explicitly prohibits Box<T>: Clone would have a problem. But no, apparently if the object does not explicitly implements Box<T>: Clone then I have a problem, because this is the official impl Clone for Box:
impl<T, A> Clone for Box<T, A> where T: Clone, A: Allocator + Clone, It requires T to be Clone. Why? Wouldn't every Box<T> be Clone, since cloning a Box requires no time? If an object does not want its box to be clone then it could implement !Clone for it, but the default should be impl Clone for Box<T> for any T.
since cloning a Box requires no time?What makes you think cloning has to do with time? Cloning has to do with if an object can, well, make a clone of itself. Are you thinking of something likeRcthat can clone itself independent of the inner object?Rcin Rust, notBox. In fact,Rc<T>isClonefor all typesT.