Module show_notes::e009
source · Expand description
Composing a Rustic tune
- Date: 2016-01-09
- Subject: Getting into the nitty-gritty with Rust’s traits.
- Audio
§Notes
Last time, we looked at generics and traits at a high level. This time, we
dig deeper on traits, looking specifically at std::iter::Iterator
as an
example of a powerful trait that can be composed across types, and then at
how we might compose multiple traits on a single type.
We also talk about the syntax for traits, the use of marker traits, some of the things you can’t presently do with traits, and even just a smidge about the future of traits in Rust. All that in less than 20 minutes!
You’ll find today’s source example fairly interesting, I think: it’s just one type, but it uses almost every concept discussed on the show today!
§Links
- Nick Cameron: “Thoughts on Rust in 2016”
- “Upcoming breakage starting in Rust 1.7, from RFCs 1214 and 136”
- The Rust Book:
- Traits
- Trait objects (dynamic dispatch)
- The Rust reference:
- RFC: impl specialization
- Aaron Turon: “Specialize to reuse”
§Sponsors
- Aleksey Pirogov
- Chris Palmer
- Derek Morr
- Hamza Sheikh
- Luca Schmid
- Micael Bergeron
- Ralph Giles (“rillian”)
- reddraggone9
- William Roe
§Become a sponsor
§Follow
- New Rustacean:
- Twitter: @newrustacean
- App.net: @newrustacean
- Email: hello@newrustacean.com
- Twitter: @newrustacean
- Chris Krycho
- Twitter: @chriskrycho
- App.net: @chriskrycho
- Twitter: @chriskrycho
Structs§
- Define a simple struct on which to implement
Iterator
… and more!
Traits§
- Define a simple trait so we can see how it works.
Functions§
- Demonstrate using a for loop over an (infinite!) iterator.