Skip to content

Commit ef1ce8f

Browse files
committed
Backport changes to md
1 parent 6d0dc04 commit ef1ce8f

8 files changed

+152
-139
lines changed

nostarch/chapter14.md

Lines changed: 106 additions & 95 deletions
Large diffs are not rendered by default.

nostarch/docx/chapter14.docx

414 Bytes
Binary file not shown.

src/ch14-00-more-about-cargo.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# More About Cargo and Crates.io
22

3-
So far we’ve used only the most basic features of Cargo to build, run, and test
4-
our code, but it can do a lot more. In this chapter, we’ll discuss some of its
5-
other, more advanced features to show you how to do the following:
3+
So far, we’ve used only the most basic features of Cargo to build, run, and
4+
test our code, but it can do a lot more. In this chapter, we’ll discuss some of
5+
its other, more advanced features to show you how to do the following:
66

77
- Customize your build through release profiles
88
- Publish libraries on [crates.io](https://crates.io/)<!-- ignore -->

src/ch14-01-release-profiles.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ various options for compiling code. Each profile is configured independently of
66
the others.
77

88
Cargo has two main profiles: the `dev` profile Cargo uses when you run `cargo
9-
build` and the `release` profile Cargo uses when you run `cargo build
9+
build`, and the `release` profile Cargo uses when you run `cargo build
1010
--release`. The `dev` profile is defined with good defaults for development,
1111
and the `release` profile has good defaults for release builds.
1212

src/ch14-02-publishing-to-crates-io.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ For convenience, running `cargo doc --open` will build the HTML for your
4545
current crate’s documentation (as well as the documentation for all of your
4646
crate’s dependencies) and open the result in a web browser. Navigate to the
4747
`add_one` function and you’ll see how the text in the documentation comments is
48-
rendered, as shown in Figure 14-1:
48+
rendered, as shown in Figure 14-1.
4949

5050
<img alt="Rendered HTML documentation for the `add_one` function of `my_crate`" src="img/trpl14-01.png" class="center" />
5151

@@ -100,20 +100,20 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
100100
```
101101

102102
Now, if we change either the function or the example so the `assert_eq!` in the
103-
example panics and run `cargo test` again, we’ll see that the doc tests catch
103+
example panics, and run `cargo test` again, we’ll see that the doc tests catch
104104
that the example and the code are out of sync with each other!
105105

106106
#### Commenting Contained Items
107107

108-
The style of doc comment `//!` adds documentation to the item that contains the
109-
comments rather than to the items following the comments. We typically use
108+
The style of doc comment `//!` adds documentation to the item that *contains*
109+
the comments rather than to the items *following* the comments. We typically use
110110
these doc comments inside the crate root file (_src/lib.rs_ by convention) or
111111
inside a module to document the crate or the module as a whole.
112112

113113
For example, to add documentation that describes the purpose of the `my_crate`
114114
crate that contains the `add_one` function, we add documentation comments that
115115
start with `//!` to the beginning of the _src/lib.rs_ file, as shown in Listing
116-
14-2:
116+
14-2.
117117

118118
<Listing number="14-2" file-name="src/lib.rs" caption="Documentation for the `my_crate` crate as a whole">
119119

@@ -150,14 +150,14 @@ are and might have difficulty finding the pieces they want to use if your crate
150150
has a large module hierarchy.
151151

152152
In Chapter 7, we covered how to make items public using the `pub` keyword, and
153-
bring items into a scope with the `use` keyword. However, the structure that
154-
makes sense to you while you’re developing a crate might not be very convenient
155-
for your users. You might want to organize your structs in a hierarchy
156-
containing multiple levels, but then people who want to use a type you’ve
157-
defined deep in the hierarchy might have trouble finding out that type exists.
158-
They might also be annoyed at having to enter `use`
159-
`my_crate::some_module::another_module::UsefulType;` rather than `use`
160-
`my_crate::UsefulType;`.
153+
how to bring items into a scope with the `use` keyword. However, the structure
154+
that makes sense to you while you’re developing a crate might not be very
155+
convenient for your users. You might want to organize your structs in a
156+
hierarchy containing multiple levels, but then people who want to use a type
157+
you’ve defined deep in the hierarchy might have trouble finding out that type
158+
exists. They might also be annoyed at having to enter `use
159+
my_crate::some_module::another_module::UsefulType;` rather than `use
160+
my_crate::UsefulType;`.
161161

162162
The good news is that if the structure _isn’t_ convenient for others to use
163163
from another library, you don’t have to rearrange your internal organization:
@@ -169,7 +169,7 @@ defined in the other location instead.
169169
For example, say we made a library named `art` for modeling artistic concepts.
170170
Within this library are two modules: a `kinds` module containing two enums
171171
named `PrimaryColor` and `SecondaryColor` and a `utils` module containing a
172-
function named `mix`, as shown in Listing 14-3:
172+
function named `mix`, as shown in Listing 14-3.
173173

174174
<Listing number="14-3" file-name="src/lib.rs" caption="An `art` library with items organized into `kinds` and `utils` modules">
175175

@@ -180,7 +180,7 @@ function named `mix`, as shown in Listing 14-3:
180180
</Listing>
181181

182182
Figure 14-3 shows what the front page of the documentation for this crate
183-
generated by `cargo doc` would look like:
183+
generated by `cargo doc` would look like.
184184

185185
<img alt="Rendered documentation for the `art` crate that lists the `kinds` and `utils` modules" src="img/trpl14-03.png" class="center" />
186186

@@ -194,7 +194,7 @@ see them.
194194
Another crate that depends on this library would need `use` statements that
195195
bring the items from `art` into scope, specifying the module structure that’s
196196
currently defined. Listing 14-4 shows an example of a crate that uses the
197-
`PrimaryColor` and `mix` items from the `art` crate:
197+
`PrimaryColor` and `mix` items from the `art` crate.
198198

199199
<Listing number="14-4" file-name="src/main.rs" caption="A crate using the `art` crate’s items with its internal structure exported">
200200

@@ -215,7 +215,7 @@ module names in the `use` statements.
215215

216216
To remove the internal organization from the public API, we can modify the
217217
`art` crate code in Listing 14-3 to add `pub use` statements to re-export the
218-
items at the top level, as shown in Listing 14-5:
218+
items at the top level, as shown in Listing 14-5.
219219

220220
<Listing number="14-5" file-name="src/lib.rs" caption="Adding `pub use` statements to re-export items">
221221

@@ -236,7 +236,7 @@ that lists the re-exports</span>
236236

237237
The `art` crate users can still see and use the internal structure from Listing
238238
14-3 as demonstrated in Listing 14-4, or they can use the more convenient
239-
structure in Listing 14-5, as shown in Listing 14-6:
239+
structure in Listing 14-5, as shown in Listing 14-6.
240240

241241
<Listing number="14-6" file-name="src/main.rs" caption="A program using the re-exported items from the `art` crate">
242242

@@ -370,8 +370,8 @@ license = "MIT OR Apache-2.0"
370370
```
371371

372372
[Cargo’s documentation](https://doc.rust-lang.org/cargo/) describes other
373-
metadata you can specify to ensure others can discover and use your crate more
374-
easily.
373+
metadata you can specify to ensure that others can discover and use your crate
374+
more easily.
375375

376376
### Publishing to Crates.io
377377

@@ -382,11 +382,11 @@ Publishing a crate uploads a specific version to
382382

383383
Be careful, because a publish is _permanent_. The version can never be
384384
overwritten, and the code cannot be deleted except in certain circumstances.
385-
One major goal of [crates.io](https://crates.io/)<!-- ignore --> is to act as a
386-
permanent archive of code so that builds of all projects that depend on crates
387-
from [crates.io](https://crates.io/)<!-- ignore --> will continue to work.
388-
Allowing version deletions would make fulfilling that goal impossible. However,
389-
there is no limit to the number of crate versions you can publish.
385+
One major goal of Crates.io is to act as a permanent archive of code so that
386+
builds of all projects that depend on crates from
387+
[crates.io](https://crates.io/)<!-- ignore --> will continue to work. Allowing
388+
version deletions would make fulfilling that goal impossible. However, there is
389+
no limit to the number of crate versions you can publish.
390390

391391
Run the `cargo publish` command again. It should succeed now:
392392

@@ -421,7 +421,7 @@ anyone can easily add your crate as a dependency of their project.
421421
When you’ve made changes to your crate and are ready to release a new version,
422422
you change the `version` value specified in your _Cargo.toml_ file and
423423
republish. Use the [Semantic Versioning rules][semver] to decide what an
424-
appropriate next version number is based on the kinds of changes you’ve made.
424+
appropriate next version number is, based on the kinds of changes you’ve made.
425425
Then run `cargo publish` to upload the new version.
426426

427427
<!-- Old link, do not remove -->
@@ -469,5 +469,5 @@ $ cargo yank --vers 1.0.1 --undo
469469
A yank _does not_ delete any code. It cannot, for example, delete accidentally
470470
uploaded secrets. If that happens, you must reset those secrets immediately.
471471

472-
[spdx]: http://spdx.org/licenses/
473-
[semver]: http://semver.org/
472+
[spdx]: https://spdx.org/licenses/
473+
[semver]: https://semver.org/

src/ch14-03-cargo-workspaces.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ configure the entire workspace. This file won’t have a `[package]` section.
2828
Instead, it will start with a `[workspace]` section that will allow us to add
2929
members to the workspace. We also make a point to use the latest and greatest
3030
version of Cargo’s resolver algorithm in our workspace by setting the
31-
`resolver` to `"3"`.
31+
`resolver` value to `"3"`.
3232

3333
<span class="filename">Filename: Cargo.toml</span>
3434

@@ -49,13 +49,13 @@ copy output below
4949

5050
```console
5151
$ cargo new adder
52-
Creating binary (application) `adder` package
52+
Created binary (application) `adder` package
5353
Adding `adder` as member of workspace at `file:///projects/add`
5454
```
5555

5656
Running `cargo new` inside a workspace also automatically adds the newly created
5757
package to the `members` key in the `[workspace]` definition in the workspace
58-
`Cargo.toml`, like this:
58+
_Cargo.toml_, like this:
5959

6060
```toml
6161
{{#include ../listings/ch14-more-about-cargo/output-only-01-adder-crate/add/Cargo.toml}}
@@ -100,7 +100,7 @@ copy output below
100100

101101
```console
102102
$ cargo new add_one --lib
103-
Creating library `add_one` package
103+
Created library `add_one` package
104104
Adding `add_one` as member of workspace at `file:///projects/add`
105105
```
106106

@@ -138,7 +138,7 @@ In the _add_one/src/lib.rs_ file, let’s add an `add_one` function:
138138
```
139139

140140
Now we can have the `adder` package with our binary depend on the `add_one`
141-
package that has our library. First we’ll need to add a path dependency on
141+
package that has our library. First, we’ll need to add a path dependency on
142142
`add_one` to _adder/Cargo.toml_.
143143

144144
<span class="filename">Filename: adder/Cargo.toml</span>
@@ -154,7 +154,7 @@ Next, let’s use the `add_one` function (from the `add_one` crate) in the
154154
`adder` crate. Open the _adder/src/main.rs_ file and change the `main`
155155
function to call the `add_one` function, as in Listing 14-7.
156156

157-
<Listing number="14-7" file-name="adder/src/main.rs" caption="Using the `add_one` library crate in the `adder` crate">
157+
<Listing number="14-7" file-name="adder/src/main.rs" caption="Using the `add_one` library crate from the `adder` crate">
158158

159159
```rust,ignore
160160
{{#rustdoc_include ../listings/ch14-more-about-cargo/listing-14-07/add/adder/src/main.rs}}
@@ -370,10 +370,11 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; fini
370370
This output shows `cargo test` only ran the tests for the `add_one` crate and
371371
didn’t run the `adder` crate tests.
372372

373-
If you publish the crates in the workspace to [crates.io](https://crates.io/),
374-
each crate in the workspace will need to be published separately. Like `cargo
375-
test`, we can publish a particular crate in our workspace by using the `-p`
376-
flag and specifying the name of the crate we want to publish.
373+
If you publish the crates in the workspace to
374+
[crates.io](https://crates.io/)<!-- ignore -->, each crate in the workspace
375+
will need to be published separately. Like `cargo test`, we can publish a
376+
particular crate in our workspace by using the `-p` flag and specifying the
377+
name of the crate we want to publish.
377378

378379
For additional practice, add an `add_two` crate to this workspace in a similar
379380
way as the `add_one` crate!

src/ch14-04-installing-binaries.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ binary target, or both.
1818
All binaries installed with `cargo install` are stored in the installation
1919
root’s _bin_ folder. If you installed Rust using _rustup.rs_ and don’t have any
2020
custom configurations, this directory will be *$HOME/.cargo/bin*. Ensure that
21-
directory is in your `$PATH`to be able to run programs you’ve installed with`cargo install`.
21+
directory is in your `$PATH` to be able to run programs you’ve installed with
22+
`cargo install`.
2223

2324
For example, in Chapter 12 we mentioned that there’s a Rust implementation of
2425
the `grep` tool called `ripgrep` for searching files. To install `ripgrep`, we

src/ch14-05-extending-cargo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ modify it. If a binary in your `$PATH` is named `cargo-something`, you can run
55
it as if it were a Cargo subcommand by running `cargo something`. Custom
66
commands like this are also listed when you run `cargo --list`. Being able to
77
use `cargo install` to install extensions and then run them just like the
8-
built-in Cargo tools is a super convenient benefit of Cargo’s design!
8+
built-in Cargo tools is a super-convenient benefit of Cargo’s design!
99

1010
## Summary
1111

0 commit comments

Comments
 (0)