From 3144d3ae63963eae6bc8469a48dc0e586d77596d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Mon, 10 Aug 2020 10:24:21 -0400 Subject: [PATCH] chore: Run rustfmt on exercises --- exercises/conversions/from_str.rs | 1 - exercises/conversions/try_from_into.rs | 2 +- exercises/conversions/using_as.rs | 4 +--- exercises/enums/enums2.rs | 4 ++-- exercises/enums/enums3.rs | 13 ++++++------- exercises/generics/generics1.rs | 1 - exercises/generics/generics2.rs | 2 +- exercises/generics/generics3.rs | 10 ++++++++-- exercises/macros/macros4.rs | 4 ++-- exercises/standard_library_types/box1.rs | 5 ++++- exercises/structs/structs3.rs | 6 +++++- exercises/traits/traits2.rs | 3 --- 12 files changed, 30 insertions(+), 25 deletions(-) diff --git a/exercises/conversions/from_str.rs b/exercises/conversions/from_str.rs index 014d054..af9eee6 100644 --- a/exercises/conversions/from_str.rs +++ b/exercises/conversions/from_str.rs @@ -82,5 +82,4 @@ mod tests { fn missing_name_and_invalid_age() { ",one".parse::().unwrap(); } - } diff --git a/exercises/conversions/try_from_into.rs b/exercises/conversions/try_from_into.rs index 9e452f2..b830c16 100644 --- a/exercises/conversions/try_from_into.rs +++ b/exercises/conversions/try_from_into.rs @@ -2,7 +2,7 @@ // Basically, this is the same as From. The main difference is that this should return a Result type // instead of the target type itself. // You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html -use std::convert::{TryInto, TryFrom}; +use std::convert::{TryFrom, TryInto}; #[derive(Debug)] struct Color { diff --git a/exercises/conversions/using_as.rs b/exercises/conversions/using_as.rs index 922abae..b3c197f 100644 --- a/exercises/conversions/using_as.rs +++ b/exercises/conversions/using_as.rs @@ -7,9 +7,7 @@ // I AM NOT DONE fn average(values: &[f64]) -> f64 { - let total = values - .iter() - .fold(0.0, |a, b| a + b); + let total = values.iter().fold(0.0, |a, b| a + b); total / values.len() } diff --git a/exercises/enums/enums2.rs b/exercises/enums/enums2.rs index 52ccb22..ec32d95 100644 --- a/exercises/enums/enums2.rs +++ b/exercises/enums/enums2.rs @@ -16,10 +16,10 @@ impl Message { fn main() { let messages = [ - Message::Move{ x: 10, y: 30 }, + Message::Move { x: 10, y: 30 }, Message::Echo(String::from("hello world")), Message::ChangeColor(200, 255, 255), - Message::Quit + Message::Quit, ]; for message in &messages { diff --git a/exercises/enums/enums3.rs b/exercises/enums/enums3.rs index e9621b8..178b40c 100644 --- a/exercises/enums/enums3.rs +++ b/exercises/enums/enums3.rs @@ -9,13 +9,13 @@ enum Message { struct Point { x: u8, - y: u8 + y: u8, } struct State { color: (u8, u8, u8), position: Point, - quit: bool + quit: bool, } impl State { @@ -46,14 +46,14 @@ mod tests { #[test] fn test_match_message_call() { - let mut state = State{ + let mut state = State { quit: false, - position: Point{ x: 0, y: 0 }, - color: (0, 0, 0) + position: Point { x: 0, y: 0 }, + color: (0, 0, 0), }; state.process(Message::ChangeColor((255, 0, 255))); state.process(Message::Echo(String::from("hello world"))); - state.process(Message::Move(Point{ x: 10, y: 15 })); + state.process(Message::Move(Point { x: 10, y: 15 })); state.process(Message::Quit); assert_eq!(state.color, (255, 0, 255)); @@ -61,5 +61,4 @@ mod tests { assert_eq!(state.position.y, 15); assert_eq!(state.quit, true); } - } diff --git a/exercises/generics/generics1.rs b/exercises/generics/generics1.rs index 1e6ae9d..967287e 100644 --- a/exercises/generics/generics1.rs +++ b/exercises/generics/generics1.rs @@ -7,4 +7,3 @@ fn main() { let mut shopping_list: Vec = Vec::new(); shopping_list.push("milk"); } - diff --git a/exercises/generics/generics2.rs b/exercises/generics/generics2.rs index 20c2127..0cb59ad 100644 --- a/exercises/generics/generics2.rs +++ b/exercises/generics/generics2.rs @@ -4,7 +4,7 @@ // I AM NOT DONE struct Wrapper { - value: u32 + value: u32, } impl Wrapper { diff --git a/exercises/generics/generics3.rs b/exercises/generics/generics3.rs index 760028e..5c745e2 100644 --- a/exercises/generics/generics3.rs +++ b/exercises/generics/generics3.rs @@ -33,7 +33,10 @@ mod tests { student_name: "Tom Wriggle".to_string(), student_age: 12, }; - assert_eq!(report_card.print(), "Tom Wriggle (12) - achieved a grade of 2.1"); + assert_eq!( + report_card.print(), + "Tom Wriggle (12) - achieved a grade of 2.1" + ); } #[test] @@ -44,6 +47,9 @@ mod tests { student_name: "Gary Plotter".to_string(), student_age: 11, }; - assert_eq!(report_card.print(), "Gary Plotter (11) - achieved a grade of A+"); + assert_eq!( + report_card.print(), + "Gary Plotter (11) - achieved a grade of A+" + ); } } diff --git a/exercises/macros/macros4.rs b/exercises/macros/macros4.rs index 3a74807..1b550f4 100644 --- a/exercises/macros/macros4.rs +++ b/exercises/macros/macros4.rs @@ -6,10 +6,10 @@ macro_rules! my_macro { () => { println!("Check out my macro!"); - } + }; ($val:expr) => { println!("Look at this other macro: {}", $val); - } + }; } fn main() { diff --git a/exercises/standard_library_types/box1.rs b/exercises/standard_library_types/box1.rs index f2654ce..f312f3d 100644 --- a/exercises/standard_library_types/box1.rs +++ b/exercises/standard_library_types/box1.rs @@ -26,7 +26,10 @@ pub enum List { fn main() { println!("This is an empty cons list: {:?}", create_empty_list()); - println!("This is a non-empty cons list: {:?}", create_non_empty_list()); + println!( + "This is a non-empty cons list: {:?}", + create_non_empty_list() + ); } pub fn create_empty_list() -> List { diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 883c803..36d46e9 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -17,7 +17,11 @@ impl Package { if weight_in_grams <= 0 { // Something goes here... } else { - return Package {sender_country, recipient_country, weight_in_grams}; + return Package { + sender_country, + recipient_country, + weight_in_grams, + }; } } diff --git a/exercises/traits/traits2.rs b/exercises/traits/traits2.rs index b9a13a4..916c3c4 100644 --- a/exercises/traits/traits2.rs +++ b/exercises/traits/traits2.rs @@ -18,9 +18,6 @@ trait AppendBar { //TODO: Add your code here - - - #[cfg(test)] mod tests { use super::*;