[Solved] Cloning inside of a Rc

#1
  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 ?

#2

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

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

2 Likes
#3

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

#4

yes

1 Like