e019: Let's `Clone` a `Cow`
The final pieces of the story for (single-threaded) memory management in Rust.
Notes
Sometimes, we actually do need to copy types. Wouldn't it be nice if Rust gave us a convenient way to do that when it's convenient, or when the cost is low enough that the ergonomic tradeoffs are worth it? Well, perhaps unsurprisingly, it does! The Copy and Clone traits, plus the Cow type, give us everything we need!
Links
underhanded.rs
The typess
std::marker::Copy
"Copy types" in the book
"Stack-Only Data: Copy" in the new book
7.2.0.2 Moved and copied types:
When a local variable is used as an rvalue, the variable will be copied if its type implements Copy. All others are moved.
Extended example in "Traits" section of new book
std::clone::Clone
std::borrow::Cow
Default implementations
discussion in the current book
discussion in the new book
Supertraits
from the discussion in the reference (6.1.9 Traits):
Traits may inherit from other traits.... The syntax
Comments