This commit is contained in:
Dhghomon 2021-01-01 05:59:07 +00:00
parent b0b7712347
commit eebc40a86b
5 changed files with 10 additions and 10 deletions

View File

@ -174,7 +174,7 @@
<p>In this book we will only look at the most popular crates, the crates that everyone who uses Rust knows.</p> <p>In this book we will only look at the most popular crates, the crates that everyone who uses Rust knows.</p>
<p>To begin learning external crates, we will start with the most common one: <code>rand</code>.</p> <p>To begin learning external crates, we will start with the most common one: <code>rand</code>.</p>
<h3><a class="header" href="#rand" id="rand">rand</a></h3> <h3><a class="header" href="#rand" id="rand">rand</a></h3>
<p>Did you notice that we didn't use any random numbers yet? That's because random numbers aren't in the standard library. But there are a lot of crates that are &quot;almost standard library&quot; because everybody uses them. In any case, it's very easy to bring in a crate. If you have Rust on your computer, there is a file called <code>cargo.toml</code> that has this information. A <code>cargo.toml</code> file looks like this when you start:</p> <p>Did you notice that we didn't use any random numbers yet? That's because random numbers aren't in the standard library. But there are a lot of crates that are &quot;almost standard library&quot; because everybody uses them. In any case, it's very easy to bring in a crate. If you have Rust on your computer, there is a file called <code>Cargo.toml</code> that has this information. A <code>Cargo.toml</code> file looks like this when you start:</p>
<pre><code class="language-text">[package] <pre><code class="language-text">[package]
name = &quot;rust_book&quot; name = &quot;rust_book&quot;
version = &quot;0.1.0&quot; version = &quot;0.1.0&quot;
@ -198,7 +198,7 @@ edition = &quot;2018&quot;
rand = &quot;0.7.3&quot; rand = &quot;0.7.3&quot;
</code></pre> </code></pre>
<p>And then Cargo will do the rest for you. Then you can start writing code like <a href="https://docs.rs/rand/0.7.3/rand/">this example code</a> on the <code>rand</code> document website. To get to the documents you can click on the <code>docs</code> button in <a href="https://crates.io/crates/rand">the page on crates.io</a>.</p> <p>And then Cargo will do the rest for you. Then you can start writing code like <a href="https://docs.rs/rand/0.7.3/rand/">this example code</a> on the <code>rand</code> document website. To get to the documents you can click on the <code>docs</code> button in <a href="https://crates.io/crates/rand">the page on crates.io</a>.</p>
<p>So that's enough about Cargo: we are still using just the Playground. Luckily, the Playground already has the top 100 crates installed. So you don't need to write in <code>cargo.toml</code> yet. On the Playground you can imagine that it has a long list like this with 100 crates:</p> <p>So that's enough about Cargo: we are still using just the Playground. Luckily, the Playground already has the top 100 crates installed. So you don't need to write in <code>Cargo.toml</code> yet. On the Playground you can imagine that it has a long list like this with 100 crates:</p>
<pre><code class="language-text">[dependencies] <pre><code class="language-text">[dependencies]
rand = &quot;0.7.3&quot; rand = &quot;0.7.3&quot;
some_other_crate = &quot;0.1.0&quot; some_other_crate = &quot;0.1.0&quot;
@ -207,7 +207,7 @@ another_nice_crate = &quot;1.7&quot;
<p>That means that to use <code>rand</code>, you can just do this.</p> <p>That means that to use <code>rand</code>, you can just do this.</p>
<pre><pre class="playground"><code class="language-rust">use rand; // This means the whole crate rand <pre><pre class="playground"><code class="language-rust">use rand; // This means the whole crate rand
// On your computer you can't just write this; // On your computer you can't just write this;
// you need to write in the cargo.toml file first // you need to write in the Cargo.toml file first
fn main() { fn main() {
for _ in 0..5 { for _ in 0..5 {

View File

@ -217,7 +217,7 @@ fn main() {
<p>Some other things you need to know are:</p> <p>Some other things you need to know are:</p>
<ul> <ul>
<li><code>cargo new</code>. You do this to create a new Rust project. After <code>new</code>, write the name of the project and <code>cargo</code> will make the folder and all the files you need.</li> <li><code>cargo new</code>. You do this to create a new Rust project. After <code>new</code>, write the name of the project and <code>cargo</code> will make the folder and all the files you need.</li>
<li><code>cargo clean</code>. When you add crates to <code>cargo.toml</code>, the computer will download all the files it needs and they can take a lot of space. If you don't want them on your computer anymore, type <code>cargo clean</code>.</li> <li><code>cargo clean</code>. When you add crates to <code>Cargo.toml</code>, the computer will download all the files it needs and they can take a lot of space. If you don't want them on your computer anymore, type <code>cargo clean</code>.</li>
</ul> </ul>
<p>One more thing about the compiler: it only takes the most time when you use <code>cargo build</code> or <code>cargo run</code> the first time. After that it will remember, and it will compile fast again. But if you use <code>cargo clean</code> and then run <code>cargo build</code>, it will have to compile slowly one more time.</p> <p>One more thing about the compiler: it only takes the most time when you use <code>cargo build</code> or <code>cargo run</code> the first time. After that it will remember, and it will compile fast again. But if you use <code>cargo clean</code> and then run <code>cargo build</code>, it will have to compile slowly one more time.</p>

View File

@ -9484,7 +9484,7 @@ mod tests {
<p>In this book we will only look at the most popular crates, the crates that everyone who uses Rust knows.</p> <p>In this book we will only look at the most popular crates, the crates that everyone who uses Rust knows.</p>
<p>To begin learning external crates, we will start with the most common one: <code>rand</code>.</p> <p>To begin learning external crates, we will start with the most common one: <code>rand</code>.</p>
<h3><a class="header" href="#rand" id="rand">rand</a></h3> <h3><a class="header" href="#rand" id="rand">rand</a></h3>
<p>Did you notice that we didn't use any random numbers yet? That's because random numbers aren't in the standard library. But there are a lot of crates that are &quot;almost standard library&quot; because everybody uses them. In any case, it's very easy to bring in a crate. If you have Rust on your computer, there is a file called <code>cargo.toml</code> that has this information. A <code>cargo.toml</code> file looks like this when you start:</p> <p>Did you notice that we didn't use any random numbers yet? That's because random numbers aren't in the standard library. But there are a lot of crates that are &quot;almost standard library&quot; because everybody uses them. In any case, it's very easy to bring in a crate. If you have Rust on your computer, there is a file called <code>Cargo.toml</code> that has this information. A <code>Cargo.toml</code> file looks like this when you start:</p>
<pre><code class="language-text">[package] <pre><code class="language-text">[package]
name = &quot;rust_book&quot; name = &quot;rust_book&quot;
version = &quot;0.1.0&quot; version = &quot;0.1.0&quot;
@ -9508,7 +9508,7 @@ edition = &quot;2018&quot;
rand = &quot;0.7.3&quot; rand = &quot;0.7.3&quot;
</code></pre> </code></pre>
<p>And then Cargo will do the rest for you. Then you can start writing code like <a href="https://docs.rs/rand/0.7.3/rand/">this example code</a> on the <code>rand</code> document website. To get to the documents you can click on the <code>docs</code> button in <a href="https://crates.io/crates/rand">the page on crates.io</a>.</p> <p>And then Cargo will do the rest for you. Then you can start writing code like <a href="https://docs.rs/rand/0.7.3/rand/">this example code</a> on the <code>rand</code> document website. To get to the documents you can click on the <code>docs</code> button in <a href="https://crates.io/crates/rand">the page on crates.io</a>.</p>
<p>So that's enough about Cargo: we are still using just the Playground. Luckily, the Playground already has the top 100 crates installed. So you don't need to write in <code>cargo.toml</code> yet. On the Playground you can imagine that it has a long list like this with 100 crates:</p> <p>So that's enough about Cargo: we are still using just the Playground. Luckily, the Playground already has the top 100 crates installed. So you don't need to write in <code>Cargo.toml</code> yet. On the Playground you can imagine that it has a long list like this with 100 crates:</p>
<pre><code class="language-text">[dependencies] <pre><code class="language-text">[dependencies]
rand = &quot;0.7.3&quot; rand = &quot;0.7.3&quot;
some_other_crate = &quot;0.1.0&quot; some_other_crate = &quot;0.1.0&quot;
@ -9517,7 +9517,7 @@ another_nice_crate = &quot;1.7&quot;
<p>That means that to use <code>rand</code>, you can just do this.</p> <p>That means that to use <code>rand</code>, you can just do this.</p>
<pre><pre class="playground"><code class="language-rust">use rand; // This means the whole crate rand <pre><pre class="playground"><code class="language-rust">use rand; // This means the whole crate rand
// On your computer you can't just write this; // On your computer you can't just write this;
// you need to write in the cargo.toml file first // you need to write in the Cargo.toml file first
fn main() { fn main() {
for _ in 0..5 { for _ in 0..5 {
@ -11050,7 +11050,7 @@ fn main() {
<p>Some other things you need to know are:</p> <p>Some other things you need to know are:</p>
<ul> <ul>
<li><code>cargo new</code>. You do this to create a new Rust project. After <code>new</code>, write the name of the project and <code>cargo</code> will make the folder and all the files you need.</li> <li><code>cargo new</code>. You do this to create a new Rust project. After <code>new</code>, write the name of the project and <code>cargo</code> will make the folder and all the files you need.</li>
<li><code>cargo clean</code>. When you add crates to <code>cargo.toml</code>, the computer will download all the files it needs and they can take a lot of space. If you don't want them on your computer anymore, type <code>cargo clean</code>.</li> <li><code>cargo clean</code>. When you add crates to <code>Cargo.toml</code>, the computer will download all the files it needs and they can take a lot of space. If you don't want them on your computer anymore, type <code>cargo clean</code>.</li>
</ul> </ul>
<p>One more thing about the compiler: it only takes the most time when you use <code>cargo build</code> or <code>cargo run</code> the first time. After that it will remember, and it will compile fast again. But if you use <code>cargo clean</code> and then run <code>cargo build</code>, it will have to compile slowly one more time.</p> <p>One more thing about the compiler: it only takes the most time when you use <code>cargo build</code> or <code>cargo run</code> the first time. After that it will remember, and it will compile fast again. But if you use <code>cargo clean</code> and then run <code>cargo build</code>, it will have to compile slowly one more time.</p>
<h2><a class="header" href="#taking-user-input" id="taking-user-input">Taking user input</a></h2> <h2><a class="header" href="#taking-user-input" id="taking-user-input">Taking user input</a></h2>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long