Skip to content

Commit 0bc6fe5

Browse files
committed
Refactor to keep rand version 0.3.0
changed paragraphs with discussion of Cargo.lock file to agree with rand version 0.3.0 in the Cargo.tom file.
1 parent 7150d3c commit 0bc6fe5

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/doc/trpl/guessing-game.md

+15-17
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,16 @@ add these few lines at the bottom:
352352
```toml
353353
[dependencies]
354354

355-
rand="*"
355+
rand="0.3.0"
356356
```
357357

358358
The `[dependencies]` section of `Cargo.toml` is like the `[package]` section:
359359
everything that follows it is part of it, until the next section starts.
360360
Cargo uses the dependencies section to know what dependencies on external
361-
crates you have, and what versions you require. In this case, we’ve used `*`,
362-
which means that we’ll use the latest version of `rand`. Cargo understands
363-
[Semantic Versioning][semver], which is a standard for writing version
364-
numbers. If we wanted a specific version or range of versions, we could be
365-
more specific here. [Cargo’s documentation][cargodoc] contains more details.
361+
crates you have, and what versions you require. In this case, we’ve used version `0.3.0`.
362+
Cargo understands [Semantic Versioning][semver], which is a standard for writing version
363+
numbers. If we wanted to use the latest version we could use `*` or we could use a range
364+
of versions. [Cargo’s documentation][cargodoc] contains more details.
366365

367366
[semver]: http://semver.org
368367
[cargodoc]: http://doc.crates.io/crates-io.html
@@ -372,15 +371,13 @@ Now, without changing any of our code, let’s build our project:
372371
```bash
373372
$ cargo build
374373
Updating registry `https://github.com/rust-lang/crates.io-index`
375-
Downloading rand v0.3.8
374+
Downloading rand v0.3.0
376375
Downloading libc v0.1.6
377376
Compiling libc v0.1.6
378-
Compiling rand v0.3.8
377+
Compiling rand v0.3.0
379378
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
380379
```
381380

382-
(You may see different versions, of course.)
383-
384381
Lots of new output! Now that we have an external dependency, Cargo fetches the
385382
latest versions of everything from the registry, which is a copy of data from
386383
[Crates.io][cratesio]. Crates.io is where people in the Rust ecosystem
@@ -410,19 +407,19 @@ $ cargo build
410407
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
411408
```
412409

413-
So, we told Cargo we wanted any version of `rand`, and so it fetched the latest
414-
version at the time this was written, `v0.3.8`. But what happens when next
415-
week, version `v0.3.9` comes out, with an important bugfix? While getting
416-
bugfixes is important, what if `0.3.9` contains a regression that breaks our
417-
code?
410+
Let's pretend that we told Cargo we wanted the latest version of `rand` (using `*`)
411+
for a bit. It would have fetched `v0.3.8` (at the time this was written).
412+
But what happens when next week, version `v0.3.9` comes out, with an important
413+
bugfix? While getting bugfixes is important, what if `0.3.9` contains a regression
414+
that breaks our code?
418415

419416
The answer to this problem is the `Cargo.lock` file you’ll now find in your
420417
project directory. When you build your project for the first time, Cargo
421418
figures out all of the versions that fit your criteria, and then writes them
422419
to the `Cargo.lock` file. When you build your project in the future, Cargo
423420
will see that the `Cargo.lock` file exists, and then use that specific version
424421
rather than do all the work of figuring out versions again. This lets you
425-
have a repeatable build automatically. In other words, we’ll stay at `0.3.8`
422+
have a repeatable build automatically. In other words, we’ll stay at `0.3.0`
426423
until we explicitly upgrade, and so will anyone who we share our code with,
427424
thanks to the lock file.
428425

@@ -442,7 +439,8 @@ projects which are assembled out of a number of sub-packages.
442439
[doccargo]: http://doc.crates.io
443440
[doccratesio]: http://doc.crates.io/crates-io.html
444441

445-
Let’s get on to actually _using_ `rand`. Here’s our next step:
442+
Let’s get on to actually _using_ `rand`. Keep the version as `0.3.0` for this
443+
project. Here’s our next step:
446444

447445
```rust,ignore
448446
extern crate rand;

0 commit comments

Comments
 (0)