@@ -28,7 +28,8 @@ Next, in the *add* directory, we create the *Cargo.toml* file that will
28
28
configure the entire workspace. This file won’t have a ` [package] ` section or
29
29
the metadata we’ve seen in other * Cargo.toml* files. Instead, it will start
30
30
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* :
32
33
33
34
<span class =" filename " >Filename: Cargo.toml</span >
34
35
@@ -65,7 +66,7 @@ in your *add* directory should look like this:
65
66
```
66
67
67
68
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*
69
70
directory. Even if we were to run ` cargo build ` from inside the * adder*
70
71
directory, the compiled artifacts would still end up in * add/target* rather
71
72
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
75
76
its own * target* directory. By sharing one * target* directory, the crates can
76
77
avoid unnecessary rebuilding.
77
78
78
- ### Creating the Second Crate in the Workspace
79
+ ### Creating the Second Package in the Workspace
79
80
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 ` .
81
82
Change the top-level * Cargo.toml* to specify the * add-one* path in the
82
83
` members ` list:
83
84
@@ -125,9 +126,10 @@ In the *add-one/src/lib.rs* file, let’s add an `add_one` function:
125
126
{{#rustdoc_include .. / listings / ch14 - more - about - cargo / no - listing - 02 - workspace - with - two - crates / add / add - one / src / lib . rs}}
126
127
```
127
128
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* .
131
133
132
134
<span class =" filename " >Filename: adder/Cargo.toml</span >
133
135
@@ -149,8 +151,8 @@ function to call the `add_one` function, as in Listing 14-7.
149
151
{{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-07/add/adder/src/main.rs}}
150
152
```
151
153
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 >
154
156
155
157
Let’s build the workspace by running ` cargo build ` in the top-level * add*
156
158
directory!
@@ -187,12 +189,12 @@ Hello, world! 10 plus one is 11!
187
189
188
190
This runs the code in * adder/src/main.rs* , which depends on the ` add-one ` crate.
189
191
190
- #### Depending on an External Crate in a Workspace
192
+ #### Depending on an External Package in a Workspace
191
193
192
194
Notice that the workspace has only one * Cargo.lock* file at the top level of
193
195
the workspace rather than having a * Cargo.lock* in each crate’s directory. This
194
196
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*
196
198
files, Cargo will resolve both of those to one version of ` rand ` and record
197
199
that in the one * Cargo.lock* . Making all crates in the workspace use the same
198
200
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
237
239
` add-one ` on ` rand ` . However, even though ` rand ` is used somewhere in the
238
240
workspace, we can’t use it in other crates in the workspace unless we add
239
241
` 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:
241
243
242
244
<!-- manual-regeneration
243
245
cd listings/ch14-more-about-cargo/output-only-03-use-rand/add
@@ -256,14 +258,14 @@ error[E0432]: unresolved import `rand`
256
258
| ^^^^ no `rand` external crate
257
259
```
258
260
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
261
263
add ` rand ` to the list of dependencies for ` adder ` in * Cargo.lock* , but no
262
264
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.
267
269
268
270
#### Adding a Test to a Workspace
269
271
0 commit comments