\n\n\n
The final pieces of the story for (single-threaded) memory management in Rust.
\nNotes\nSometimes, 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!
The typess
\n7.2.0.2 Moved and copied types:
\n\nWhen a local variable is used as an rvalue, the variable will be copied if its type implements
\nCopy. All others are moved.
Default implementations
\nSupertraits
\nfrom the discussion in the reference (6.1.9 Traits):
\n\nTraits may inherit from other traits.... The syntax
\nCircle : Shapemeans that types that implementCirclemust also have an implementation forShape. Multiple supertraits are separated by+, traitCircle : Shape + PartialEq { }. In an implementation ofCirclefor a given typeT, methods can refer toShapemethods, since the typechecker checks that any type with an implementation ofCirclealso has an implementation ofShape...
discussion of trait super- and subtyping in the new book (note: still to-be-written at the time this episode was published)
Marker traits
\nin the reference: 9 Special Traits
Previous episodes on traits:
\n(Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!)
\nBecome a sponsor\n\nContact\n