Summary

  • for loops iterate over the values in an Iterator

  • Iterator is a trait that represents a stream of values

  • Range expressions like 1..11 or 1..=10 are one kind of Iterator

  • Many types provide an IntoIterator implementation, including Vec and slices

  • With the rule of 3, you can get:

    • Moved iterators of values (.into_iter())

    • Reference iterators (borrow the value, or .iter())

    • Mutable reference iterators (mutably borrow the value, or .iter_mut())

  • To iterate on a string slice, you need to choose either .chars() or .bytes()

  • You can write generic iterator functions using Iterator as a trait bound

  • Iterators have a lot more power for the future, allowing a lot of functional programming

Get hands-on with 1200+ tech skills courses.