Answers for "rust•armanazi•type•wrapper•vs•clone"

0

rust•armanazi•type•wrapper•vs•clone

If implementing Clone would be prohibitively expensive, Rc<T> can be a handy alternative. This allows two places to “share” ownership.
We could have called a.clone() rather than Rc::clone(&a), but Rust’s convention is to use Rc::clone in this case. The implementation of Rc::clone doesn’t make a deep copy of all the data like most types’ implementations of clone do.
The call to Rc::clone only increments the reference count,
which doesn’t take much time. Deep copies of data can take a lot of time.
By using Rc::clone for reference counting, we can visually distinguish between the deep-copy kinds of clones and the kinds of clones that increase the reference count
Posted by: Guest on March-09-2022

Code answers related to "rust•armanazi•type•wrapper•vs•clone"

Browse Popular Code Answers by Language