For loop clarification


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?


Check out

The desugaring does the unwrapping, yes.


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