@@ -410,24 +410,29 @@ $ cargo build
410
410
Compiling guessing_game v0.1.0 (file:///home/you/projects/guessing_game)
411
411
```
412
412
413
- So, we told Cargo we wanted any version of ` rand ` , and so it fetched the
414
- latest version at the time this was written, ` v0.3.8 ` . But what happens
415
- when next week, version ` v0.4.0 ` comes out, which changes something with
416
- ` rand ` , and it includes a breaking change? After all, a ` v0.y.z ` version
417
- in SemVer can change every release.
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?
418
418
419
419
The answer to this problem is the ` Cargo.lock ` file you’ll now find in your
420
420
project directory. When you build your project for the first time, Cargo
421
421
figures out all of the versions that fit your criteria, and then writes them
422
422
to the ` Cargo.lock ` file. When you build your project in the future, Cargo
423
423
will see that the ` Cargo.lock ` file exists, and then use that specific version
424
424
rather than do all the work of figuring out versions again. This lets you
425
- have a repeatable build automatically.
425
+ have a repeatable build automatically. In other words, we’ll stay at ` 0.3.8 `
426
+ until we explicitly upgrade, and so will anyone who we share our code with,
427
+ thanks to the lock file.
426
428
427
- What about when we _ do_ want to use ` v0.4.0 ` ? Cargo has another command,
429
+ What about when we _ do_ want to use ` v0.3.9 ` ? Cargo has another command,
428
430
` update ` , which says ‘ignore the lock, figure out all the latest versions that
429
431
fit what we’ve specified. If that works, write those versions out to the lock
430
- file’.
432
+ file’. But, by default, Cargo will only look for versions larger than ` 0.3.0 `
433
+ and smaller than ` 0.4.0 ` . If we want to move to ` 0.4.x ` , we’d have to update
434
+ the ` Cargo.toml ` directly. When we do, the next time we ` cargo build ` , Cargo
435
+ will update the index and re-evaluate our ` rand ` requirements.
431
436
432
437
There’s a lot more to say about [ Cargo] [ doccargo ] and [ its
433
438
ecosystem] [ doccratesio ] , but for now, that’s all we need to know. Cargo makes
0 commit comments