<h2id="a-tour-of-the-standard-library"><aclass="header"href="#a-tour-of-the-standard-library">A tour of the standard library</a></h2>
<p>Now that you know a lot of Rust, you will be able to understand most things inside the standard library. The code inside it isn't so scary anymore. Let's take a look at some of the parts in it that we haven't learned yet. This tour will go over most parts of the standard library that you don't need to install Rust for. We will revisit a lot of items we already know so we can learn them with greater understanding.</p>
<p>One thing about arrays to note is that they don't implement <code>Iterator.</code>. That means that if you have an array, you can't use <code>for</code>. But you can use methods like <code>.iter()</code> on them. Or you can use<code>&</code> to get a slice. Actually, the compiler will tell you exactly that if you try to use<code>for</code>:</p>
<p>In the past (before Rust 1.53), arrays didn't implement <code>Iterator</code> and you needed to use methods like <code>.iter()</code> on them in for <code>loops</code>. (People also used<code>&</code> to get a slice in<code>for</code> loops). So this didn't work in the past:</p>
let my_cities = ["Beirut", "Tel Aviv", "Nicosia"];
for city in my_cities {
println!("{}", city);
}
for city in &my_cities {
println!("{}", city);
}
@ -172,6 +174,9 @@ Nicosia
Beirut
Tel Aviv
Nicosia
Beirut
Tel Aviv
Nicosia
</code></pre>
<p>If you want to get variables from an array, you can put their names inside <code>[]</code> to destructure it. This is the same as using a tuple in <code>match</code> statements or to get variables from a struct.</p>
<divstyle="break-before: page; page-break-before: always;"></div><h2id="a-tour-of-the-standard-library"><aclass="header"href="#a-tour-of-the-standard-library">A tour of the standard library</a></h2>
<p>Now that you know a lot of Rust, you will be able to understand most things inside the standard library. The code inside it isn't so scary anymore. Let's take a look at some of the parts in it that we haven't learned yet. This tour will go over most parts of the standard library that you don't need to install Rust for. We will revisit a lot of items we already know so we can learn them with greater understanding.</p>
<p>One thing about arrays to note is that they don't implement <code>Iterator.</code>. That means that if you have an array, you can't use <code>for</code>. But you can use methods like <code>.iter()</code> on them. Or you can use<code>&</code> to get a slice. Actually, the compiler will tell you exactly that if you try to use<code>for</code>:</p>
<p>In the past (before Rust 1.53), arrays didn't implement <code>Iterator</code> and you needed to use methods like <code>.iter()</code> on them in for <code>loops</code>. (People also used<code>&</code> to get a slice in<code>for</code> loops). So this didn't work in the past:</p>
let my_cities = ["Beirut", "Tel Aviv", "Nicosia"];
for city in my_cities {
println!("{}", city);
}
for city in &my_cities {
println!("{}", city);
}
@ -9797,6 +9799,9 @@ Nicosia
Beirut
Tel Aviv
Nicosia
Beirut
Tel Aviv
Nicosia
</code></pre>
<p>If you want to get variables from an array, you can put their names inside <code>[]</code> to destructure it. This is the same as using a tuple in <code>match</code> statements or to get variables from a struct.</p>