@@ -352,17 +352,16 @@ add these few lines at the bottom:
352
352
``` toml
353
353
[dependencies ]
354
354
355
- rand =" * "
355
+ rand =" 0.3.0 "
356
356
```
357
357
358
358
The ` [dependencies] ` section of ` Cargo.toml ` is like the ` [package] ` section:
359
359
everything that follows it is part of it, until the next section starts.
360
360
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.
366
365
367
366
[ semver ] : http://semver.org
368
367
[ cargodoc ] : http://doc.crates.io/crates-io.html
@@ -372,15 +371,13 @@ Now, without changing any of our code, let’s build our project:
372
371
``` bash
373
372
$ cargo build
374
373
Updating registry ` https://github.com/rust-lang/crates.io-index`
375
- Downloading rand v0.3.8
374
+ Downloading rand v0.3.0
376
375
Downloading libc v0.1.6
377
376
Compiling libc v0.1.6
378
- Compiling rand v0.3.8
377
+ Compiling rand v0.3.0
379
378
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
380
379
```
381
380
382
- (You may see different versions, of course.)
383
-
384
381
Lots of new output! Now that we have an external dependency, Cargo fetches the
385
382
latest versions of everything from the registry, which is a copy of data from
386
383
[ Crates.io] [ cratesio ] . Crates.io is where people in the Rust ecosystem
@@ -410,19 +407,19 @@ $ cargo build
410
407
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
411
408
```
412
409
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?
418
415
419
416
The answer to this problem is the ` Cargo.lock ` file you’ll now find in your
420
417
project directory. When you build your project for the first time, Cargo
421
418
figures out all of the versions that fit your criteria, and then writes them
422
419
to the ` Cargo.lock ` file. When you build your project in the future, Cargo
423
420
will see that the ` Cargo.lock ` file exists, and then use that specific version
424
421
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 `
426
423
until we explicitly upgrade, and so will anyone who we share our code with,
427
424
thanks to the lock file.
428
425
@@ -442,7 +439,8 @@ projects which are assembled out of a number of sub-packages.
442
439
[ doccargo ] : http://doc.crates.io
443
440
[ doccratesio ] : http://doc.crates.io/crates-io.html
444
441
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:
446
444
447
445
``` rust,ignore
448
446
extern crate rand;
0 commit comments