20 A tour of the standard library
This chapter covers
- Review and more in-depth look at types you already know such as arrays, char, bool, numeric types, Vec, and String
- Associated constants
- A summary of the three associated items in Rust
- Recently added functions such as from_fn and then_some
- Various types you haven’t seen before like OsString and CString
Good work! You’re almost through the book and there are only five chapters left. For this chapter and the next we are now going to sit back and relax and go on a short tour of the standard library, including further detail 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.
20.1 Arrays
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.
20.1.1 Arrays now implement Iterator
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: