Wrote a piece on how to implement `Iterator` and `IntoIterator` in @rustlang for your own types. It's a bit rough, but hope it comes in useful for someone somehow!
https://github.com/yoshuawuyts/knowledge/blob/master/computers/rust/iterators.md …
Tbh it's mostly for my own reference down the line. But I'd be keen to listen if anyone has any suggestions. Mostly unsure about the `for foo in &bar` pattern. It seems so weird to me that it needs to be borrowed there.
-
-
`for book in &library` doesn’t consume.
-
You implemented `IntoIterator` for `&Library`, which means the `self` in `into_iter` is `self: &Library` -> a reference. If you want to consume it you need to `impl IntoIterator for Library` and need to return an iterator owning the library data.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.