mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-17 15:29:51 +00:00
deploy: bfedcd3dc4
This commit is contained in:
parent
b0b7712347
commit
eebc40a86b
@ -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>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>
|
||||
<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 "almost standard library" 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 "almost standard library" 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]
|
||||
name = "rust_book"
|
||||
version = "0.1.0"
|
||||
@ -198,7 +198,7 @@ edition = "2018"
|
||||
rand = "0.7.3"
|
||||
</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>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]
|
||||
rand = "0.7.3"
|
||||
some_other_crate = "0.1.0"
|
||||
@ -207,7 +207,7 @@ another_nice_crate = "1.7"
|
||||
<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
|
||||
// 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() {
|
||||
for _ in 0..5 {
|
||||
|
@ -217,7 +217,7 @@ fn main() {
|
||||
<p>Some other things you need to know are:</p>
|
||||
<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 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>
|
||||
<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>
|
||||
|
||||
|
@ -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>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>
|
||||
<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 "almost standard library" 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 "almost standard library" 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]
|
||||
name = "rust_book"
|
||||
version = "0.1.0"
|
||||
@ -9508,7 +9508,7 @@ edition = "2018"
|
||||
rand = "0.7.3"
|
||||
</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>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]
|
||||
rand = "0.7.3"
|
||||
some_other_crate = "0.1.0"
|
||||
@ -9517,7 +9517,7 @@ another_nice_crate = "1.7"
|
||||
<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
|
||||
// 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() {
|
||||
for _ in 0..5 {
|
||||
@ -11050,7 +11050,7 @@ fn main() {
|
||||
<p>Some other things you need to know are:</p>
|
||||
<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 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>
|
||||
<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>
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user