From 4599839865eb155e52ef605e032c5b543121dfe9 Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 26 Feb 2018 11:43:55 -0500 Subject: [PATCH] Looks like I didn't take a snapshot of ch2 last page review These corrections are in the page review pdf already. --- second-edition/nostarch/chapter02.md | 36 +++++++++++++++------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/second-edition/nostarch/chapter02.md b/second-edition/nostarch/chapter02.md index 7b02b9f5a..00fc48c0a 100644 --- a/second-edition/nostarch/chapter02.md +++ b/second-edition/nostarch/chapter02.md @@ -408,14 +408,15 @@ dependencies, and you haven’t changed anything about them in your *Cargo.toml* file. Cargo also knows that you haven’t changed anything about your code, so it doesn’t recompile that either. With nothing to do, it simply exits. If you open up the *src/main.rs* file, make a trivial change, then save it and build again, -you’ll only see one line of output: +you’ll only see two lines of output: ``` $ cargo build Compiling guessing_game v0.1.0 (file:///projects/guessing_game) + Finished dev [unoptimized + debuginfo] target(s) in 2.53 secs ``` -This line shows Cargo only updates the build with your tiny change to the +These lines show Cargo only updates the build with your tiny change to the *src/main.rs* file. Your dependencies haven’t changed, so Cargo knows it can reuse what it has already downloaded and compiled for those. It just rebuilds your part of the code. @@ -602,9 +603,9 @@ fn main() { println!("You guessed: {}", guess); match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), + Ordering::Equal => println!("You win!"), } } ``` @@ -622,9 +623,9 @@ Then we add five new lines at the bottom that use the `Ordering` type: ``` match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), + Ordering::Equal => println!("You win!"), } ``` @@ -718,9 +719,9 @@ fn main() { println!("You guessed: {}", guess); match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), + Ordering::Equal => println!("You win!"), } } ``` @@ -748,8 +749,9 @@ user must press the enter key to satisfy `read_line`. When the user presses enter, a newline character is added to the string. For example, if the user types 5 and presses enter, -`guess` looks like this: `5\n`. The `\n` represents “newline,” the enter key. -The `trim` method eliminates `\n`, resulting in just `5`. +`guess` looks like this: `5\n`. The `\n` represents “newline,” the +enterkey. The `trim` method eliminates `\n`, +resulting in just `5`. The `parse` method on strings parses a string into some kind of number. Because this method can parse a variety of number types, we @@ -831,9 +833,9 @@ fn main() { println!("You guessed: {}", guess); match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => println!("You win!"), + Ordering::Equal => println!("You win!"), } } } @@ -846,7 +848,7 @@ exactly what we told it to do: ask for another guess forever! It doesn’t seem like the user can quit! The user could always halt the program by using the keyboard shortcut -ctrl-C. But there’s another way to escape this +ctrl-c. But there’s another way to escape this insatiable monster that we mentioned in the `parse` discussion in “Comparing the Guess to the Secret Number”: if the user enters a non-number answer, the program will crash. The user can take advantage of that in order to quit, as shown here: @@ -914,9 +916,9 @@ fn main() { println!("You guessed: {}", guess); match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => { + Ordering::Equal => { println!("You win!"); break; } @@ -1025,9 +1027,9 @@ fn main() { println!("You guessed: {}", guess); match guess.cmp(&secret_number) { - Ordering::Less => println!("Too small!"), + Ordering::Less => println!("Too small!"), Ordering::Greater => println!("Too big!"), - Ordering::Equal => { + Ordering::Equal => { println!("You win!"); break; }