3 ms·
I feel like those clones don't get enough attention. At a glance, you don't really know what those clones are doing. Is it allocating, is just increasing refere
by tayo42 3y ago
I feel like those clones don't get enough attention. At a glance, you don't really know what those clones are doing. Is it allocating, is just increasing reference counter? Makes code hard to understand
- urthor 3y agoclone() makes an immutable, deep copy/recursive copy of the original data structure. clone() itself makes perfect sense. Why the programmer needed those clones... is a legitimate issue with Rust. In my experience so far, it's usually to hack around an interaction between the borrow checker and the output of a function constructed using dot syntax.
- dist1ll 3y ago> clone() makes an immutable, deep copy/recursive copy of the original data structure. No. clone() calls std::clone::Clone::clone. For many std collections that means deep/recursive copy. For custom data structures, it can mean anything. It depends entirely on your implementation of the Clone trait.