mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2024-11-14 04:41:49 +08:00
Update listing code in ch02
This commit is contained in:
parent
2da49dfe9d
commit
24d08cccf4
@ -25,7 +25,7 @@ fn main() {
|
|||||||
// ANCHOR_END: expect
|
// ANCHOR_END: expect
|
||||||
|
|
||||||
// ANCHOR: print_guess
|
// ANCHOR: print_guess
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
// ANCHOR_END: print_guess
|
// ANCHOR_END: print_guess
|
||||||
}
|
}
|
||||||
// ANCHOR: all
|
// ANCHOR: all
|
||||||
|
@ -11,5 +11,5 @@ fn main() {
|
|||||||
.read_line(&mut guess)
|
.read_line(&mut guess)
|
||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,10 @@ fn main() {
|
|||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
// ANCHOR: ch07-04
|
// ANCHOR: ch07-04
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
// ANCHOR_END: ch07-04
|
// ANCHOR_END: ch07-04
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ fn main() {
|
|||||||
.read_line(&mut guess)
|
.read_line(&mut guess)
|
||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
// ANCHOR: ch07-04
|
// ANCHOR: ch07-04
|
||||||
}
|
}
|
||||||
// ANCHOR_END: ch07-04
|
// ANCHOR_END: ch07-04
|
||||||
|
@ -19,7 +19,7 @@ error[E0308]: mismatched types
|
|||||||
error[E0283]: type annotations needed for `{integer}`
|
error[E0283]: type annotations needed for `{integer}`
|
||||||
--> src/main.rs:8:44
|
--> src/main.rs:8:44
|
||||||
|
|
|
|
||||||
8 | let secret_number = rand::thread_rng().gen_range(1..101);
|
8 | let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
| ------------- ^^^^^^^^^ cannot infer type for type `{integer}`
|
| ------------- ^^^^^^^^^ cannot infer type for type `{integer}`
|
||||||
| |
|
| |
|
||||||
| consider giving `secret_number` a type
|
| consider giving `secret_number` a type
|
||||||
@ -37,7 +37,7 @@ note: required by a bound in `gen_range`
|
|||||||
| ^^^^^^^^^^^^^ required by this bound in `gen_range`
|
| ^^^^^^^^^^^^^ required by this bound in `gen_range`
|
||||||
help: consider specifying the type arguments in the function call
|
help: consider specifying the type arguments in the function call
|
||||||
|
|
|
|
||||||
8 | let secret_number = rand::thread_rng().gen_range::<T, R>(1..101);
|
8 | let secret_number = rand::thread_rng().gen_range::<T, R>(1..=100);
|
||||||
| ++++++++
|
| ++++++++
|
||||||
|
|
||||||
Some errors have detailed explanations: E0283, E0308.
|
Some errors have detailed explanations: E0283, E0308.
|
||||||
|
@ -8,9 +8,9 @@ fn main() {
|
|||||||
// ANCHOR_END: here
|
// ANCHOR_END: here
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ fn main() {
|
|||||||
.expect("Failed to read line");
|
.expect("Failed to read line");
|
||||||
// ANCHOR: here
|
// ANCHOR: here
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
match guess.cmp(&secret_number) {
|
match guess.cmp(&secret_number) {
|
||||||
Ordering::Less => println!("Too small!"),
|
Ordering::Less => println!("Too small!"),
|
||||||
|
@ -5,9 +5,9 @@ use std::io;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
@ -28,7 +28,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
// ANCHOR_END: ch19
|
// ANCHOR_END: ch19
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
// --snip--
|
// --snip--
|
||||||
// ANCHOR_END: here
|
// ANCHOR_END: here
|
||||||
|
@ -5,7 +5,7 @@ use std::io;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
@ -21,7 +21,7 @@ fn main() {
|
|||||||
Err(_) => continue,
|
Err(_) => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
match guess.cmp(&secret_number) {
|
match guess.cmp(&secret_number) {
|
||||||
Ordering::Less => println!("Too small!"),
|
Ordering::Less => println!("Too small!"),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "guessing_game"
|
name = "guessing_game"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
|
@ -9,5 +9,5 @@ fn main() {
|
|||||||
|
|
||||||
io::stdin().read_line(&mut guess);
|
io::stdin().read_line(&mut guess);
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@ use std::io;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ fn main() {
|
|||||||
|
|
||||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
match guess.cmp(&secret_number) {
|
match guess.cmp(&secret_number) {
|
||||||
Ordering::Less => println!("Too small!"),
|
Ordering::Less => println!("Too small!"),
|
||||||
|
@ -5,12 +5,12 @@ use std::io;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
// ANCHOR: here
|
// ANCHOR: here
|
||||||
// --snip--
|
// --snip--
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
@ -27,7 +27,7 @@ fn main() {
|
|||||||
|
|
||||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
// ANCHOR: here
|
// ANCHOR: here
|
||||||
match guess.cmp(&secret_number) {
|
match guess.cmp(&secret_number) {
|
||||||
|
@ -5,9 +5,9 @@ use std::io;
|
|||||||
fn main() {
|
fn main() {
|
||||||
println!("Guess the number!");
|
println!("Guess the number!");
|
||||||
|
|
||||||
let secret_number = rand::thread_rng().gen_range(1..101);
|
let secret_number = rand::thread_rng().gen_range(1..=100);
|
||||||
|
|
||||||
println!("The secret number is: {}", secret_number);
|
println!("The secret number is: {secret_number}");
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Please input your guess.");
|
println!("Please input your guess.");
|
||||||
@ -20,7 +20,7 @@ fn main() {
|
|||||||
|
|
||||||
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
let guess: u32 = guess.trim().parse().expect("Please type a number!");
|
||||||
|
|
||||||
println!("You guessed: {}", guess);
|
println!("You guessed: {guess}");
|
||||||
|
|
||||||
// ANCHOR: here
|
// ANCHOR: here
|
||||||
// --snip--
|
// --snip--
|
||||||
|
Loading…
Reference in New Issue
Block a user