Skip to content

Commit 5d22a35

Browse files
committed
Backport fixes from NoStarch
This is an exhaustive pass in preparation for going the *other* way for the 2024 Edition print update, i.e. the Third Edition of the print book.
1 parent 15e16cb commit 5d22a35

File tree

61 files changed

+509
-506
lines changed

Some content is hidden

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

61 files changed

+509
-506
lines changed

ci/dictionary.txt

Lines changed: 1 addition & 0 deletions
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
Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 1 addition & 1 deletion
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
}
Lines changed: 16 additions & 15 deletions
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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
}

0 commit comments

Comments
 (0)