[Solved] Cloning inside of a Rc

  1. Suppose we have:
x: Rc<T>;
T: Clone;

In this case, given a Rc<T>, how do we create an object of T by “cloning the inside” of the Rc ?


(*rc).clone(). Dereferencing will get the object out of the Rc.

You can also use explicit T::clone(&rc).


Is the reason for () because *rc.clone() clones the Rc, then tries to deref it, thus never making an actual copy?



1 Like