For loop clarification


#1

I was reading code from an external crate which implemented the Iterator trait. It was the first time I’ve read code implementing that trait and was surprised to see that next() returns an Option. I’ve never written a for loop where I’ve had to match on the for loop binding so I’m assuming the for construct unwraps the Option before binding the value and passing it to the body of the for loop.

Is that correct?


#2

Check out http://doc.rust-lang.org/nightly/std/iter/#for-loops-and-intoiterator

The desugaring does the unwrapping, yes.


#3

Thanks. That’s exactly the docs I was looking for.