Crust of Rust: Iterators
Channel: Jon Gjengset
Date: 2020-05-27

In this third Crust of Rust video, we cover iterators and trait bounds, by re-implementing the "flatten" Iterator method from the standard library. As part of that, we cover some of the weirder trait bounds that are required, including what's needed to extend the implementation to support backwards iteration.

You can find the final code at https://gist.github.com/jonhoo/dd63b720fa4a220ea845a77e2d75831e.

0:00:00 Introduction
0:01:45 The Iterator trait
0:04:25 The IntoIterator trait
0:06:24 Generic traits vs associated types
0:13:37 Provided Iterator methods
0:14:42 Iterator::flatten
0:20:07 Associated items of generics in bounds
0:23:10 Why must O as Trait be bracketed?
0:24:28 Flattening more than two levels
0:25:24 First attempt at Flatten::next
0:29:59 Two elements in inner iterator
0:31:05 Two elements in outer iterator
0:33:29 Simplifying with ?
0:35:05 Storing the inner iterator
0:39:10 Trait bound syntax
0:40:07 Finishing corrected next
0:42:50 Ergonomics with IntoIterator
0:44:15 DoubleEndedIterator
0:46:10 First draft of DEI implementation
0:50:57 Testing double-ended iteration
0:53:58 Iterating from both ends in parallel
1:04:02 The cost of two cursors
1:06:28 Iterators are like Futures
1:07:14 Calling next and next_back concurrently
1:07:55 ref in patterns
1:09:33 Why not flatten first, then iterate
1:12:51 More ref in patterns
1:14:09 Deeper flattening
1:17:00 FlatMap
1:18:19 Ergonomics through extension traits
1:21:19 Sized in traits

You can watch the live version with comments at https://www.youtube.com/watch?v=pqHWEsXamYg