The final pieces of the story for (single-threaded) memory management in Rust.
NotesSometimes, 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!
LinksThe typess
-
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.
-
Default implementations
Supertraits
from the discussion in the reference (6.1.9 Traits):
Traits may inherit from other traits.... The syntax Circle : Shape means that types that implement Circle must also have an implementation for Shape. Multiple supertraits are separated by +, trait Circle : Shape + PartialEq { }. In an implementation of Circle for a given type T, methods can refer to Shape methods, since the typechecker checks that any type with an implementation of Circle also has an implementation of Shape...
discussion of trait super- and subtyping in the new book (note: still to-be-written at the time this episode was published)
Marker traits
in the reference: 9 Special Traits
Previous episodes on traits:
- Aleksey Pirogov
- Andreas Fischer
- Andrew Thompson
- Austin LeSure
- Ben Whitley
- Charlie Egan
- Chris Palmer
- Christopher Giffard
- Daniel Collin
- Derek Morr
- Jakub "Limeth" Hlusička
- Jordan Henderson
- Jupp Müller
- Keith Gray
- Lachlan Collins
- Luca Schmid
- Matt Rudder
- Matthew Piziak
- Max Jacobson
- Micael Bergeron
- Ovidiu Curcan
- Pascal Hertleif
- Peter Tillemans
- Philipp Keller
- Ralph Giles ("rillian")
- Raph Levien
- reddraggone9
- Steven Murawski
- Stuart Hinson
- Tyler Harper
- Vesa Kaihlavirta
- Vlad Bezden
- William Roe
- Zaki
(Thanks to the couple people donating who opted out of the reward tier, as well. You know who you are!)
Become a sponsor Contact- New Rustacean:
- Twitter: @newrustacean
- Email: [email protected]
- Chris Krycho
- GitHub: chriskrycho
- Twitter: @chriskrycho
Fler avsnitt av New Rustacean
Visa alla avsnitt av New RustaceanNew Rustacean med Chris Krycho finns tillgänglig på flera plattformar. Informationen på denna sida kommer från offentliga podd-flöden.
