Skip to content

Commit

Permalink
Update listing code in ch02
Browse files Browse the repository at this point in the history
  • Loading branch information
Sefank committed Jul 3, 2022
1 parent 2da49df commit 24d08cc
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fn main() {
.read_line(&mut guess)
.expect("Failed to read line");

println!("You guessed: {}", guess);
println!("You guessed: {guess}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -28,7 +28,7 @@ fn main() {
};
// ANCHOR_END: ch19

println!("You guessed: {}", guess);
println!("You guessed: {guess}");

// --snip--
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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!"),
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fn main() {

io::stdin().read_line(&mut guess);

println!("You guessed: {}", guess);
println!("You guessed: {guess}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.");

Expand All @@ -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!"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand All @@ -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--
Expand Down

0 comments on commit 24d08cc

Please sign in to comment.