-
Notifications
You must be signed in to change notification settings - Fork 295
Open
Description
Thanks for the excellent tutorial.
Sadly, Rust has nothing like a yield statement (yet), so we're going to have to implement the logic ourselves. Also, there's actually 3 different kinds of iterator each collection should endeavour to implement:
- IntoIter -
T- IterMut -
&mut T- Iter -
&TWe actually already have all the tools to implement IntoIter using List's interface: just call pop over and over. As such, we'll just implement IntoIter as a newtype wrapper around List
I think could do with a bit more ramp up into why you use a newtype wrapper. I'm not sure what the best way to approach it is, but maybe the following questions/comments could help:
- Mention that we could just use
self.pop(), but that the other iterator types will need to keep track of where they got to in the list. - What is a newtype struct?
- When do we use a newtype struct?
- Maybe gloss over the traits on foreign types stuff...
Metadata
Metadata
Assignees
Labels
No labels