Good work! You’re almost through the book—there are only five chapters left. For this chapter and the next, we are going to sit back and relax and go on a short tour of the standard library, including further details on some of the types we already know. You will certainly end up encountering these modules and methods as you continue to use Rust, so we might as well learn them now so that they are already familiar to you. Nothing in this chapter will be particularly difficult to learn, and we’ll keep things pretty brief and run through one type per section.
Arrays have become easier to work with over time, as we saw in the chapter on const generics. Some other nice changes have taken place that we’ll take a look at now.
In the past (before Rust 1.53), arrays didn’t implement Iterator, and you needed to use methods like .iter() on them in for loops. (Another method was to use & to get a slice in for loops). So, the following code didn’t work in the past:
fn main() { let my_cities = ["Beirut", "Tel Aviv", "Nicosia"]; for city in my_cities { println!("{}", city); } }