[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).

2 Likes

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

yes

1 Like