Skip to content

Commit 18f6e63

Browse files
authored
Merge pull request #4224 from rust-lang/nostarch-backports
NoStarch backports
2 parents d4d2c18 + 5d22a35 commit 18f6e63

File tree

63 files changed

+552
-526
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+552
-526
lines changed

ci/dictionary.txt

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ grapheme
205205
Grapheme
206206
growable
207207
gzip
208+
handcoded
208209
handoff
209210
hardcode
210211
hardcoded
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
fn main() {
2-
let lucky_number = 7; // Im feeling lucky today
2+
let lucky_number = 7; // I'm feeling lucky today
33
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
2-
// Im feeling lucky today
2+
// I'm feeling lucky today
33
let lucky_number = 7;
44
}
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
fn main() {
2-
let s1 = gives_ownership(); // gives_ownership moves its return
3-
// value into s1
2+
let s1 = gives_ownership(); // gives_ownership moves its return
3+
// value into s1
44

5-
let s2 = String::from("hello"); // s2 comes into scope
5+
let s2 = String::from("hello"); // s2 comes into scope
66

7-
let s3 = takes_and_gives_back(s2); // s2 is moved into
8-
// takes_and_gives_back, which also
9-
// moves its return value into s3
7+
let s3 = takes_and_gives_back(s2); // s2 is moved into
8+
// takes_and_gives_back, which also
9+
// moves its return value into s3
1010
} // Here, s3 goes out of scope and is dropped. s2 was moved, so nothing
1111
// happens. s1 goes out of scope and is dropped.
1212

13-
fn gives_ownership() -> String { // gives_ownership will move its
14-
// return value into the function
15-
// that calls it
13+
fn gives_ownership() -> String { // gives_ownership will move its
14+
// return value into the function
15+
// that calls it
1616

1717
let some_string = String::from("yours"); // some_string comes into scope
1818

19-
some_string // some_string is returned and
20-
// moves out to the calling
21-
// function
19+
some_string // some_string is returned and
20+
// moves out to the calling
21+
// function
2222
}
2323

24-
// This function takes a String and returns one
25-
fn takes_and_gives_back(a_string: String) -> String { // a_string comes into
26-
// scope
24+
// This function takes a String and returns a String.
25+
fn takes_and_gives_back(a_string: String) -> String {
26+
// a_string comes into
27+
// scope
2728

2829
a_string // a_string is returned and moves out to the calling function
2930
}

listings/ch04-understanding-ownership/listing-04-09/src/main.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ fn first_word(s: &str) -> &str {
1616
fn main() {
1717
let my_string = String::from("hello world");
1818

19-
// `first_word` works on slices of `String`s, whether partial or whole
19+
// `first_word` works on slices of `String`s, whether partial or whole.
2020
let word = first_word(&my_string[0..6]);
2121
let word = first_word(&my_string[..]);
2222
// `first_word` also works on references to `String`s, which are equivalent
23-
// to whole slices of `String`s
23+
// to whole slices of `String`s.
2424
let word = first_word(&my_string);
2525

2626
let my_string_literal = "hello world";
2727

28-
// `first_word` works on slices of string literals, whether partial or whole
28+
// `first_word` works on slices of string literals, whether partial or
29+
// whole.
2930
let word = first_word(&my_string_literal[0..6]);
3031
let word = first_word(&my_string_literal[..]);
3132

listings/ch04-understanding-ownership/no-listing-13-reference-scope-ends/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ fn main() {
55
let r1 = &s; // no problem
66
let r2 = &s; // no problem
77
println!("{r1} and {r2}");
8-
// variables r1 and r2 will not be used after this point
8+
// Variables r1 and r2 will not be used after this point.
99

1010
let r3 = &mut s; // no problem
1111
println!("{r3}");

listings/ch04-understanding-ownership/no-listing-15-dangling-reference-annotated/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ fn dangle() -> &String { // dangle returns a reference to a String
88
let s = String::from("hello"); // s is a new String
99

1010
&s // we return a reference to the String, s
11-
} // Here, s goes out of scope, and is dropped. Its memory goes away.
11+
} // Here, s goes out of scope, and is dropped, so its memory goes away.
1212
// Danger!
13-
// ANCHOR_END: here
13+
// ANCHOR_END: here

listings/ch07-managing-growing-projects/listing-07-05/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// ANCHOR: here
12
mod front_of_house {
23
pub mod hosting {
34
fn add_to_waitlist() {}
45
}
56
}
67

8+
// -- snip --
9+
// ANCHOR_END: here
710
pub fn eat_at_restaurant() {
811
// Absolute path
912
crate::front_of_house::hosting::add_to_waitlist();

listings/ch07-managing-growing-projects/listing-07-07/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
// ANCHOR: here
12
mod front_of_house {
23
pub mod hosting {
34
pub fn add_to_waitlist() {}
45
}
56
}
67

8+
// -- snip --
9+
// ANCHOR_END: here
710
pub fn eat_at_restaurant() {
811
// Absolute path
912
crate::front_of_house::hosting::add_to_waitlist();

listings/ch07-managing-growing-projects/listing-07-09/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ mod back_of_house {
1515
}
1616

1717
pub fn eat_at_restaurant() {
18-
// Order a breakfast in the summer with Rye toast
18+
// Order a breakfast in the summer with Rye toast.
1919
let mut meal = back_of_house::Breakfast::summer("Rye");
20-
// Change our mind about what bread we'd like
20+
// Change our mind about what bread we'd like.
2121
meal.toast = String::from("Wheat");
2222
println!("I'd like {} toast please", meal.toast);
2323

2424
// The next line won't compile if we uncomment it; we're not allowed
25-
// to see or modify the seasonal fruit that comes with the meal
25+
// to see or modify the seasonal fruit that comes with the meal.
2626
// meal.seasonal_fruit = String::from("blueberries");
2727
}

listings/ch08-common-collections/listing-08-12/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44

55
let s = data.to_string();
66

7-
// the method also works on a literal directly:
7+
// The method also works on a literal directly:
88
let s = "initial contents".to_string();
99
// ANCHOR_END: here
1010
}

listings/ch15-smart-pointers/listing-15-26/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
println!("a rc count after changing a = {}", Rc::strong_count(&a));
3939

4040
// Uncomment the next line to see that we have a cycle;
41-
// it will overflow the stack
41+
// it will overflow the stack.
4242
// println!("a next item = {:?}", a.tail());
4343
}
4444
// ANCHOR_END: here

listings/ch20-advanced-features/listing-20-32/hello_macro/hello_macro_derive/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use quote::quote;
44
#[proc_macro_derive(HelloMacro)]
55
pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
66
// Construct a representation of Rust code as a syntax tree
7-
// that we can manipulate
7+
// that we can manipulate.
88
let ast = syn::parse(input).unwrap();
99

10-
// Build the trait implementation
10+
// Build the trait implementation.
1111
impl_hello_macro(&ast)
1212
}

src/appendix-03-derivable-traits.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ that also implement `PartialEq`.
8383
Deriving `PartialOrd` implements the `partial_cmp` method, which returns an
8484
`Option<Ordering>` that will be `None` when the values given don’t produce an
8585
ordering. An example of a value that doesn’t produce an ordering, even though
86-
most values of that type can be compared, is the not-a-number (`NaN`) floating
87-
point value. Calling `partial_cmp` with any floating point number and the `NaN`
88-
floating point value will return `None`.
86+
most values of that type can be compared, is the `NaN` floating point value.
87+
Calling `partial_cmp` with any floating point number and the `NaN` floating
88+
point value will return `None`.
8989

9090
When derived on structs, `PartialOrd` compares two instances by comparing the
9191
value in each field in the order in which the fields appear in the struct
@@ -111,9 +111,9 @@ a data structure that stores data based on the sort order of the values.
111111

112112
The `Clone` trait allows you to explicitly create a deep copy of a value, and
113113
the duplication process might involve running arbitrary code and copying heap
114-
data. See the [“Ways Variables and Data Interact:
115-
Clone”][ways-variables-and-data-interact-clone]<!-- ignore --> section in
116-
Chapter 4 for more information on `Clone`.
114+
data. See [Variables and Data Interacting with
115+
Clone”][variables-and-data-interacting-with-clone]<!-- ignore --> in Chapter 4
116+
for more information on `Clone`.
117117

118118
Deriving `Clone` implements the `clone` method, which when implemented for the
119119
whole type, calls `clone` on each of the parts of the type. This means all the
@@ -125,9 +125,9 @@ returned from `to_vec` will need to own its instances, so `to_vec` calls
125125
`clone` on each item. Thus, the type stored in the slice must implement `Clone`.
126126

127127
The `Copy` trait allows you to duplicate a value by only copying bits stored on
128-
the stack; no arbitrary code is necessary. See the [“Stack-Only Data:
129-
Copy”][stack-only-data-copy]<!-- ignore --> section in Chapter 4 for more
130-
information on `Copy`.
128+
the stack; no arbitrary code is necessary. See [“Stack-Only Data:
129+
Copy”][stack-only-data-copy]<!-- ignore --> in Chapter 4 for more information on
130+
`Copy`.
131131

132132
The `Copy` trait doesn’t define any methods to prevent programmers from
133133
overloading those methods and violating the assumption that no arbitrary code
@@ -166,11 +166,11 @@ meaning all fields or values in the type must also implement `Default` to
166166
derive `Default`.
167167

168168
The `Default::default` function is commonly used in combination with the struct
169-
update syntax discussed in the [“Creating Instances From Other Instances With
170-
Struct Update
171-
Syntax”][creating-instances-from-other-instances-with-struct-update-syntax]<!-- ignore -->
172-
section in Chapter 5. You can customize a few fields of a struct and then
173-
set and use a default value for the rest of the fields by using
169+
update syntax discussed in [“Creating Instances From Other Instances With Struct
170+
Update
171+
Syntax”][creating-instances-from-other-instances-with-struct-update-syntax]<!--
172+
ignore --> in Chapter 5. You can customize a few fields of a struct and then set
173+
and use a default value for the rest of the fields by using
174174
`..Default::default()`.
175175

176176
The `Default` trait is required when you use the method `unwrap_or_default` on
@@ -180,5 +180,5 @@ The `Default` trait is required when you use the method `unwrap_or_default` on
180180

181181
[creating-instances-from-other-instances-with-struct-update-syntax]: ch05-01-defining-structs.html#creating-instances-from-other-instances-with-struct-update-syntax
182182
[stack-only-data-copy]: ch04-01-what-is-ownership.html#stack-only-data-copy
183-
[ways-variables-and-data-interact-clone]: ch04-01-what-is-ownership.html#ways-variables-and-data-interact-clone
183+
[variables-and-data-interacting-with-clone]: ch04-01-what-is-ownership.html#variables-and-data-interacting-with-clone
184184
[macros]: ch20-05-macros.html#macros

src/ch00-00-introduction.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ mean both how quickly Rust code can run and the speed at which Rust lets you
7474
write programs. The Rust compiler’s checks ensure stability through feature
7575
additions and refactoring. This is in contrast to the brittle legacy code in
7676
languages without these checks, which developers are often afraid to modify. By
77-
striving for zero-cost abstractions, higher-level features that compile to
78-
lower-level code as fast as code written manually, Rust endeavors to make safe
77+
striving for zero-cost abstractionshigher-level features that compile to
78+
lower-level code as fast as code written manuallyRust endeavors to make safe
7979
code be fast code as well.
8080

8181
The Rust language hopes to support many other users as well; those mentioned
@@ -157,13 +157,13 @@ more about lifetimes, traits, types, functions, and closures.
157157
In Chapter 21, we’ll complete a project in which we’ll implement a low-level
158158
multithreaded web server!
159159

160-
Finally, some appendices contain useful information about the language in a
161-
more reference-like format. Appendix A covers Rust’s keywords, Appendix B
162-
covers Rust’s operators and symbols, Appendix C covers derivable traits
163-
provided by the standard library, Appendix D covers some useful development
164-
tools, and Appendix E explains Rust editions. In Appendix F, you can find
165-
translations of the book, and in Appendix G we’ll cover how Rust is made and
166-
what nightly Rust is.
160+
Finally, some appendixes contain useful information about the language in a more
161+
reference-like format. **Appendix A** covers Rust’s keywords, **Appendix B**
162+
covers Rust’s operators and symbols, **Appendix C** covers derivable traits
163+
provided by the standard library, **Appendix D** covers some useful development
164+
tools, and **Appendix E** explains Rust editions. In **Appendix F**, you can
165+
find translations of the book, and in **Appendix G** we’ll cover how Rust is
166+
made and what nightly Rust is.
167167

168168
There is no wrong way to read this book: if you want to skip ahead, go for it!
169169
You might have to jump back to earlier chapters if you experience any

src/ch01-03-hello-cargo.md

-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ name = "hello_cargo"
6666
version = "0.1.0"
6767
edition = "2021"
6868

69-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
70-
7169
[dependencies]
7270
```
7371

src/ch02-00-guessing-game-tutorial.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ If `parse` is _not_ able to turn the string into a number, it will return an
857857
`Err` value that contains more information about the error. The `Err` value
858858
does not match the `Ok(num)` pattern in the first `match` arm, but it does
859859
match the `Err(_)` pattern in the second arm. The underscore, `_`, is a
860-
catchall value; in this example, we’re saying we want to match all `Err`
860+
catch-all value; in this example, we’re saying we want to match all `Err`
861861
values, no matter what information they have inside them. So the program will
862862
execute the second arm’s code, `continue`, which tells the program to go to the
863863
next iteration of the `loop` and ask for another guess. So, effectively, the

src/ch03-02-data-types.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ when it’s safe to assume the number is positive, it’s shown with no sign.
6262
Signed numbers are stored using [two’s complement][twos-complement]<!-- ignore
6363
--> representation.
6464

65-
Each signed variant can store numbers from -(2<sup>n - 1</sup>) to 2<sup>n -
66-
1</sup> - 1 inclusive, where _n_ is the number of bits that variant uses. So an
67-
`i8` can store numbers from -(2<sup>7</sup>) to 2<sup>7</sup> - 1, which equals
68-
-128 to 127. Unsigned variants can store numbers from 0 to 2<sup>n</sup> - 1,
69-
so a `u8` can store numbers from 0 to 2<sup>8</sup> - 1, which equals 0 to 255.
65+
Each signed variant can store numbers from (2<sup>n 1</sup>) to 2<sup>n
66+
1</sup> 1 inclusive, where _n_ is the number of bits that variant uses. So an
67+
`i8` can store numbers from (2<sup>7</sup>) to 2<sup>7</sup> 1, which equals
68+
128 to 127. Unsigned variants can store numbers from 0 to 2<sup>n</sup> 1,
69+
so a `u8` can store numbers from 0 to 2<sup>8</sup> 1, which equals 0 to 255.
7070

7171
Additionally, the `isize` and `usize` types depend on the architecture of the
7272
computer your program is running on, which is denoted in the table as “arch”:
@@ -120,7 +120,7 @@ some sort of collection.
120120
>
121121
> - Wrap in all modes with the `wrapping_*` methods, such as `wrapping_add`.
122122
> - Return the `None` value if there is overflow with the `checked_*` methods.
123-
> - Return the value and a boolean indicating whether there was overflow with
123+
> - Return the value and a Boolean indicating whether there was overflow with
124124
> the `overflowing_*` methods.
125125
> - Saturate at the value’s minimum or maximum values with the `saturating_*`
126126
> methods.

src/ch03-04-comments.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ comment continues until the end of the line. For comments that extend beyond a
1616
single line, you’ll need to include `//` on each line, like this:
1717

1818
```rust
19-
// So were doing something complicated here, long enough that we need
19+
// So we're doing something complicated here, long enough that we need
2020
// multiple lines of comments to do it! Whew! Hopefully, this comment will
21-
// explain whats going on.
21+
// explain what's going on.
2222
```
2323

2424
Comments can also be placed at the end of lines containing code:

src/ch04-03-slices.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ A _string slice_ is a reference to part of a `String`, and it looks like this:
114114
Rather than a reference to the entire `String`, `hello` is a reference to a
115115
portion of the `String`, specified in the extra `[0..5]` bit. We create slices
116116
using a range within brackets by specifying `[starting_index..ending_index]`,
117-
where `starting_index` is the first position in the slice and `ending_index` is
118-
one more than the last position in the slice. Internally, the slice data
117+
where _`starting_index`_ is the first position in the slice and _`ending_index`_
118+
is one more than the last position in the slice. Internally, the slice data
119119
structure stores the starting position and the length of the slice, which
120-
corresponds to `ending_index` minus `starting_index`. So, in the case of `let
120+
corresponds to _`ending_index`_ minus _`starting_index`_. So, in the case of `let
121121
world = &s[6..11];`, `world` would be a slice that contains a pointer to the
122122
byte at index 6 of `s` with a length value of `5`.
123123

src/ch06-02-match.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ possibility in order for the code to be valid. Especially in the case of
193193
`None` case, it protects us from assuming that we have a value when we might
194194
have null, thus making the billion-dollar mistake discussed earlier impossible.
195195

196-
### Catch-all Patterns and the `_` Placeholder
196+
### Catch-All Patterns and the `_` Placeholder
197197

198198
Using enums, we can also take special actions for a few particular values, but
199199
for all other values take one default action. Imagine we’re implementing a game

src/ch07-00-managing-growing-projects-with-packages-crates-and-modules.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ optionally one library crate. As a package grows, you can extract parts into
1212
separate crates that become external dependencies. This chapter covers all
1313
these techniques. For very large projects comprising a set of interrelated
1414
packages that evolve together, Cargo provides _workspaces_, which we’ll cover
15-
in the [“Cargo Workspaces”][workspaces]<!-- ignore --> section in Chapter 14.
15+
in [“Cargo Workspaces”][workspaces]<!-- ignore --> in Chapter 14.
1616

1717
We’ll also discuss encapsulating implementation details, which lets you reuse
1818
code at a higher level: once you’ve implemented an operation, other code can

0 commit comments

Comments
 (0)