Update listing code in ch02

This commit is contained in:
Sefank 2022-07-03 23:41:32 +08:00
parent 2da49dfe9d
commit 24d08cccf4
No known key found for this signature in database
GPG Key ID: 8257999DC508E901
12 changed files with 27 additions and 26 deletions

View File

@ -25,7 +25,7 @@ fn main() {
// ANCHOR_END: expect
// ANCHOR: print_guess
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR_END: print_guess
}
// ANCHOR: all

View File

@ -11,5 +11,5 @@ fn main() {
.read_line(&mut guess)
.expect("Failed to read line");
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
}

View File

@ -8,10 +8,10 @@ fn main() {
println!("Guess the number!");
// 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
println!("The secret number is: {}", secret_number);
println!("The secret number is: {secret_number}");
println!("Please input your guess.");
@ -21,7 +21,7 @@ fn main() {
.read_line(&mut guess)
.expect("Failed to read line");
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR: ch07-04
}
// ANCHOR_END: ch07-04

View File

@ -19,7 +19,7 @@ error[E0308]: mismatched types
error[E0283]: type annotations needed for `{integer}`
--> 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}`
| |
| 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`
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.

View File

@ -8,9 +8,9 @@ fn main() {
// ANCHOR_END: here
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.");
@ -21,7 +21,7 @@ fn main() {
.expect("Failed to read line");
// ANCHOR: here
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),

View File

@ -5,9 +5,9 @@ use std::io;
fn main() {
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 {
println!("Please input your guess.");
@ -28,7 +28,7 @@ fn main() {
};
// ANCHOR_END: ch19
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// --snip--
// ANCHOR_END: here

View File

@ -5,7 +5,7 @@ use std::io;
fn main() {
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 {
println!("Please input your guess.");
@ -21,7 +21,7 @@ fn main() {
Err(_) => continue,
};
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),

View File

@ -1,6 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "guessing_game"
version = "0.1.0"

View File

@ -9,5 +9,5 @@ fn main() {
io::stdin().read_line(&mut guess);
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
}

View File

@ -5,9 +5,9 @@ use std::io;
fn main() {
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.");
@ -22,7 +22,7 @@ fn main() {
let guess: u32 = guess.trim().parse().expect("Please type a number!");
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
match guess.cmp(&secret_number) {
Ordering::Less => println!("Too small!"),

View File

@ -5,12 +5,12 @@ use std::io;
fn main() {
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
// --snip--
println!("The secret number is: {}", secret_number);
println!("The secret number is: {secret_number}");
loop {
println!("Please input your guess.");
@ -27,7 +27,7 @@ fn main() {
let guess: u32 = guess.trim().parse().expect("Please type a number!");
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR: here
match guess.cmp(&secret_number) {

View File

@ -5,9 +5,9 @@ use std::io;
fn main() {
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 {
println!("Please input your guess.");
@ -20,7 +20,7 @@ fn main() {
let guess: u32 = guess.trim().parse().expect("Please type a number!");
println!("You guessed: {}", guess);
println!("You guessed: {guess}");
// ANCHOR: here
// --snip--