Skip to content

Commit

Permalink
Commit the changes that rustfmt made to all the listings
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Jan 26, 2020
1 parent dec27ee commit fd3e920
Show file tree
Hide file tree
Showing 219 changed files with 840 additions and 843 deletions.
19 changes: 18 additions & 1 deletion listings/ch02-guessing-game-tutorial/listing-02-01/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
// ANCHOR: all
// ANCHOR: io
use std::io;
// ANCHOR_END: io

// ANCHOR: main
fn main() {
// ANCHOR_END: main
// ANCHOR: print
println!("Guess the number!");

println!("Please input your guess.");
// ANCHOR_END: print

// ANCHOR: string
let mut guess = String::new();
// ANCHOR_END: string

io::stdin().read_line(&mut guess)
// ANCHOR: read
io::stdin()
.read_line(&mut guess)
// ANCHOR_END: read
// ANCHOR: expect
.expect("Failed to read line");
// ANCHOR_END: expect

// ANCHOR: print_guess
println!("You guessed: {}", guess);
// ANCHOR_END: print_guess
}
// ANCHOR: all
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

println!("You guessed: {}", guess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

println!("You guessed: {}", guess);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// ANCHOR: here
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {

// --snip--
// ANCHOR_END: here
println!("Guess the number!");
Expand All @@ -17,7 +16,8 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
// ANCHOR: here

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");
Expand All @@ -17,7 +17,8 @@ fn main() {
// ANCHOR: here
// --snip--

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

// ANCHOR: ch19
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");
Expand All @@ -12,7 +12,8 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

let guess: u32 = match guess.trim().parse() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");
Expand All @@ -16,11 +16,11 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");
Expand All @@ -21,11 +21,11 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

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);

Expand All @@ -37,4 +37,4 @@ fn main() {
}
}
}
// ANCHOR_END: here
// ANCHOR_END: here
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io;
use std::cmp::Ordering;
use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");
Expand All @@ -14,11 +14,11 @@ fn main() {

let mut guess = String::new();

io::stdin().read_line(&mut guess)
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");

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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
fn main() {
let condition = true;
let number = if condition {
5
} else {
6
};
let number = if condition { 5 } else { 6 };

println!("The value of number is: {}", number);
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
$ cargo run
Compiling branches v0.1.0 (file:///projects/branches)
error[E0308]: if and else have incompatible types
--> src/main.rs:7:9
--> src/main.rs:4:44
|
4 | let number = if condition {
| __________________-
5 | | 5
| | - expected because of this
6 | | } else {
7 | | "six"
| | ^^^^^ expected integer, found &str
8 | | };
| |_____- if and else have incompatible types
4 | let number = if condition { 5 } else { "six" };
| - ^^^^^ expected integer, found &str
| |
| expected because of this
|
= note: expected type `{integer}`
found type `&str`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
fn main() {
let condition = true;

let number = if condition {
5
} else {
"six"
};
let number = if condition { 5 } else { "six" };

println!("The value of number is: {}", number);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ fn first_word(s: &String) -> usize {
}
// ANCHOR_END: here

fn main() {
}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ fn main() {
s.push_str(", world!"); // push_str() appends a literal to a String

println!("{}", s); // This will print `hello, world!`
// ANCHOR_END: here
// ANCHOR_END: here
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ fn main() {

{
let r1 = &mut s;

} // r1 goes out of scope here, so we can make a new reference with no problems.

let r2 = &mut s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ fn first_word(s: &String) -> &str {
}
// ANCHOR_END: here

fn main() {
}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ struct User {
}
// ANCHOR_END: here

fn main() {
}
fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fn main() {

user1.email = String::from("anotheremail@example.com");
// ANCHOR_END: here
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ fn build_user(email: String, username: String) -> User {
// ANCHOR_END: here

fn main() {
let user1 = build_user(String::from("someone@example.com"), String::from("someusername123"));
}
let user1 = build_user(
String::from("someone@example.com"),
String::from("someusername123"),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ fn build_user(email: String, username: String) -> User {
// ANCHOR_END: here

fn main() {
let user1 = build_user(String::from("someone@example.com"), String::from("someusername123"));
}
let user1 = build_user(
String::from("someone@example.com"),
String::from("someusername123"),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ struct Rectangle {
}

fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect1 = Rectangle {
width: 30,
height: 50,
};

println!(
"The area of the rectangle is {} square pixels.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
$ cargo run
Compiling structs v0.1.0 (file:///projects/structs)
error[E0277]: `Rectangle` doesn't implement `std::fmt::Display`
--> src/main.rs:9:29
|
9 | println!("rect1 is {}", rect1);
| ^^^^^ `Rectangle` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Rectangle`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required by `std::fmt::Display::fmt`
--> src/main.rs:12:29
|
12 | println!("rect1 is {}", rect1);
| ^^^^^ `Rectangle` cannot be formatted with the default formatter
|
= help: the trait `std::fmt::Display` is not implemented for `Rectangle`
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
= note: required by `std::fmt::Display::fmt`

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ struct Rectangle {
}

fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect1 = Rectangle {
width: 30,
height: 50,
};

println!("rect1 is {}", rect1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ struct Rectangle {
}

fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect1 = Rectangle {
width: 30,
height: 50,
};

println!("rect1 is {:?}", rect1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ impl Rectangle {
}

fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect1 = Rectangle {
width: 30,
height: 50,
};

println!(
"The area of the rectangle is {} square pixels.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
let rect2 = Rectangle { width: 10, height: 40 };
let rect3 = Rectangle { width: 60, height: 45 };
let rect1 = Rectangle {
width: 30,
height: 50,
};
let rect2 = Rectangle {
width: 10,
height: 40,
};
let rect3 = Rectangle {
width: 60,
height: 45,
};

println!("Can rect1 hold rect2? {}", rect1.can_hold(&rect2));
println!("Can rect1 hold rect3? {}", rect1.can_hold(&rect3));
Expand Down
Loading

0 comments on commit fd3e920

Please sign in to comment.