mirror of
https://github.com/rust-lang/book.git
synced 2026-06-13 11:50:27 -04:00
Looks like I didn't take a snapshot of ch2 last page review
These corrections are in the page review pdf already.
This commit is contained in:
@@ -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 <span class="keystroke">enter</span> key to satisfy
|
||||
`read_line`. When the user presses <span class="keystroke">enter</span>, a
|
||||
newline character is added to the string. For example, if the user types <span
|
||||
class="keystroke">5</span> and presses <span class="keystroke"> enter</span>,
|
||||
`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
|
||||
<span class="keystroke">enter</span>key. 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
|
||||
<span class="keystroke">ctrl-C</span>. But there’s another way to escape this
|
||||
<span class="keystroke">ctrl-c</span>. 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user