Skip to content

Commit 5f16469

Browse files
committed
Auto merge of #171 - miller-time:rustfmt-exercises, r=komaeda
chore: Clean up some formatting in exercises I noticed some formatting that isn't consistent with the `rustfmt` style and tried my best to run it on the files in the exercises directory (which does fail for files that can't compile!), which just caught some minor whitespace things here and there. Note: also can't just apply `rustfmt` blindly because of the blank lines that lead to the hint comments
2 parents 752bc27 + eb13c2b commit 5f16469

File tree

11 files changed

+19
-19
lines changed

11 files changed

+19
-19
lines changed

exercises/functions/functions5.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn square(num: i32) -> i32 {
4040

4141
// This is a really common error that can be fixed by removing one character.
4242
// It happens because Rust distinguishes between expressions and statements: expressions return
43-
// a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
43+
// a value based on its operand, and statements simply return a () type which behaves just like `void` in C/C++ language.
4444
// We want to return a value of `i32` type from the `square` function, but it is returning a `()` type...
4545
// They are not the same. There are two solutions:
4646
// 1. Add a `return` ahead of `num * num;`

exercises/if/if1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// if1.rs
22

3-
pub fn bigger(a: i32, b:i32) -> i32 {
3+
pub fn bigger(a: i32, b: i32) -> i32 {
44
// Complete this function to return the bigger number!
55
// Do not use:
66
// - return

exercises/modules/modules2.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// modules2.rs
22
// Make me compile! Scroll down for hints :)
33

4-
mod delicious_snacks {
4+
mod delicious_snacks {
55
use self::fruits::PEAR as fruit;
66
use self::veggies::CUCUMBER as veggie;
77

@@ -17,9 +17,11 @@ mod delicious_snacks {
1717
}
1818

1919
fn main() {
20-
println!("favorite snacks: {} and {}",
21-
delicious_snacks::fruit,
22-
delicious_snacks::veggie);
20+
println!(
21+
"favorite snacks: {} and {}",
22+
delicious_snacks::fruit,
23+
delicious_snacks::veggie
24+
);
2325
}
2426

2527

exercises/move_semantics/move_semantics1.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111
vec1.push(88);
1212

1313
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
14-
1514
}
1615

1716
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

exercises/move_semantics/move_semantics2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn main() {
1212
vec1.push(88);
1313

1414
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
15-
1615
}
1716

1817
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

exercises/move_semantics/move_semantics3.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn main() {
1313
vec1.push(88);
1414

1515
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
16-
1716
}
1817

1918
fn fill_vec(vec: Vec<i32>) -> Vec<i32> {

exercises/move_semantics/move_semantics4.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ fn main() {
1313
vec1.push(88);
1414

1515
println!("{} has length {} content `{:?}`", "vec1", vec1.len(), vec1);
16-
1716
}
1817

1918
// `fill_vec()` no longer take `vec: Vec<i32>` as argument

exercises/primitive_types/primitive_types6.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ fn main() {
3838

3939

4040

41-
// While you could use a destructuring `let` for the tuple here, try
42-
// indexing into it instead, as explained in the last example of the
41+
// While you could use a destructuring `let` for the tuple here, try
42+
// indexing into it instead, as explained in the last example of the
4343
// Data Types -> The Tuple Type section of the book:
4444
// https://doc.rust-lang.org/stable/book/ch03-02-data-types.html#the-tuple-type
4545
// Now you have another tool in your toolbox!

exercises/standard_library_types/arc1.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ fn main() {
1313
let mut joinhandles = Vec::new();
1414

1515
for offset in 0..8 {
16-
joinhandles.push(
17-
thread::spawn(move || {
16+
joinhandles.push(thread::spawn(move || {
1817
let mut i = offset;
1918
let mut sum = 0;
2019
while i < child_numbers.len() {

exercises/standard_library_types/iterators3.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ pub struct NotDivisibleError {
2323
// This function should calculate `a` divided by `b` if `a` is
2424
// evenly divisible by b.
2525
// Otherwise, it should return a suitable error.
26-
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {
27-
}
26+
pub fn divide(a: i32, b: i32) -> Result<i32, DivisionError> {}
2827

2928
#[cfg(test)]
3029
mod tests {
@@ -40,7 +39,7 @@ mod tests {
4039
fn test_not_divisible() {
4140
assert_eq!(
4241
divide(81, 6),
43-
Err(DivisionError::NotDivisible(NotDivisibleError{
42+
Err(DivisionError::NotDivisible(NotDivisibleError {
4443
dividend: 81,
4544
divisor: 6
4645
}))

exercises/test3.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
// you think each value is. That is, add either `string_slice` or `string`
88
// before the parentheses on each line. If you're right, it will compile!
99

10-
fn string_slice(arg: &str) { println!("{}", arg); }
11-
fn string(arg: String) { println!("{}", arg); }
10+
fn string_slice(arg: &str) {
11+
println!("{}", arg);
12+
}
13+
fn string(arg: String) {
14+
println!("{}", arg);
15+
}
1216

1317
fn main() {
1418
("blue");

0 commit comments

Comments
 (0)