Skip to content

Commit 84ee234

Browse files
authored
Merge pull request #2373 from rust-lang/gh2287
Clarify some package/crate distinctions in chapter 14
2 parents c15f1bc + 833e663 commit 84ee234

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/ch14-03-cargo-workspaces.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Next, in the *add* directory, we create the *Cargo.toml* file that will
2828
configure the entire workspace. This file won’t have a `[package]` section or
2929
the metadata we’ve seen in other *Cargo.toml* files. Instead, it will start
3030
with a `[workspace]` section that will allow us to add members to the workspace
31-
by specifying the path to our binary crate; in this case, that path is *adder*:
31+
by specifying the path to the package with our binary crate; in this case,
32+
that path is *adder*:
3233

3334
<span class="filename">Filename: Cargo.toml</span>
3435

@@ -65,7 +66,7 @@ in your *add* directory should look like this:
6566
```
6667

6768
The workspace has one *target* directory at the top level for the compiled
68-
artifacts to be placed into; the `adder` crate doesn’t have its own *target*
69+
artifacts to be placed into; the `adder` package doesn’t have its own *target*
6970
directory. Even if we were to run `cargo build` from inside the *adder*
7071
directory, the compiled artifacts would still end up in *add/target* rather
7172
than *add/adder/target*. Cargo structures the *target* directory in a workspace
@@ -75,9 +76,9 @@ recompile each of the other crates in the workspace to have the artifacts in
7576
its own *target* directory. By sharing one *target* directory, the crates can
7677
avoid unnecessary rebuilding.
7778

78-
### Creating the Second Crate in the Workspace
79+
### Creating the Second Package in the Workspace
7980

80-
Next, let’s create another member crate in the workspace and call it `add-one`.
81+
Next, let’s create another member package in the workspace and call it `add-one`.
8182
Change the top-level *Cargo.toml* to specify the *add-one* path in the
8283
`members` list:
8384

@@ -125,9 +126,10 @@ In the *add-one/src/lib.rs* file, let’s add an `add_one` function:
125126
{{#rustdoc_include ../listings/ch14-more-about-cargo/no-listing-02-workspace-with-two-crates/add/add-one/src/lib.rs}}
126127
```
127128

128-
Now that we have a library crate in the workspace, we can have the binary crate
129-
`adder` depend on the library crate `add-one`. First, we’ll need to add a path
130-
dependency on `add-one` to *adder/Cargo.toml*.
129+
Now that we have another package in the workspace, we can have the `adder`
130+
package with our binary depend on the `add-one` package, that has our
131+
library. First, we’ll need to add a path dependency on `add-one` to
132+
*adder/Cargo.toml*.
131133

132134
<span class="filename">Filename: adder/Cargo.toml</span>
133135

@@ -149,8 +151,8 @@ function to call the `add_one` function, as in Listing 14-7.
149151
{{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-07/add/adder/src/main.rs}}
150152
```
151153

152-
<span class="caption">Listing 14-7: Using the `add-one` library crate from the
153-
`adder` crate</span>
154+
<span class="caption">Listing 14-7: Using the `add-one` library crate from the
155+
`adder` crate</span>
154156

155157
Let’s build the workspace by running `cargo build` in the top-level *add*
156158
directory!
@@ -187,12 +189,12 @@ Hello, world! 10 plus one is 11!
187189

188190
This runs the code in *adder/src/main.rs*, which depends on the `add-one` crate.
189191

190-
#### Depending on an External Crate in a Workspace
192+
#### Depending on an External Package in a Workspace
191193

192194
Notice that the workspace has only one *Cargo.lock* file at the top level of
193195
the workspace rather than having a *Cargo.lock* in each crate’s directory. This
194196
ensures that all crates are using the same version of all dependencies. If we
195-
add the `rand` crate to the *adder/Cargo.toml* and *add-one/Cargo.toml*
197+
add the `rand` package to the *adder/Cargo.toml* and *add-one/Cargo.toml*
196198
files, Cargo will resolve both of those to one version of `rand` and record
197199
that in the one *Cargo.lock*. Making all crates in the workspace use the same
198200
dependencies means the crates in the workspace will always be compatible with
@@ -237,7 +239,7 @@ The top-level *Cargo.lock* now contains information about the dependency of
237239
`add-one` on `rand`. However, even though `rand` is used somewhere in the
238240
workspace, we can’t use it in other crates in the workspace unless we add
239241
`rand` to their *Cargo.toml* files as well. For example, if we add `use rand;`
240-
to the *adder/src/main.rs* file for the `adder` crate, we’ll get an error:
242+
to the *adder/src/main.rs* file for the `adder` package, we’ll get an error:
241243

242244
<!-- manual-regeneration
243245
cd listings/ch14-more-about-cargo/output-only-03-use-rand/add
@@ -256,14 +258,14 @@ error[E0432]: unresolved import `rand`
256258
| ^^^^ no `rand` external crate
257259
```
258260

259-
To fix this, edit the *Cargo.toml* file for the `adder` crate and indicate that
260-
`rand` is a dependency for that crate as well. Building the `adder` crate will
261+
To fix this, edit the *Cargo.toml* file for the `adder` package and indicate
262+
that `rand` is a dependency for it as well. Building the `adder` package will
261263
add `rand` to the list of dependencies for `adder` in *Cargo.lock*, but no
262264
additional copies of `rand` will be downloaded. Cargo has ensured that every
263-
crate in the workspace using the `rand` crate will be using the same version.
264-
Using the same version of `rand` across the workspace saves space because we
265-
won’t have multiple copies and ensures that the crates in the workspace will be
266-
compatible with each other.
265+
crate in every package in the workspace using the `rand` package will be
266+
using the same version. Using the same version of `rand` across the workspace
267+
saves space because we won’t have multiple copies and ensures that the crates
268+
in the workspace will be compatible with each other.
267269

268270
#### Adding a Test to a Workspace
269271

0 commit comments

Comments
 (0)