From ca6bf966dd83fe17e5fe97fb7f42939e07cf7943 Mon Sep 17 00:00:00 2001 From: Eddy Petrisor Date: Wed, 22 May 2019 14:50:23 +0300 Subject: [PATCH 1/4] Cargo fmt the rustlings application code Signed-off-by: Eddy Petrisor --- src/exercise.rs | 6 +++--- src/run.rs | 2 +- src/verify.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/exercise.rs b/src/exercise.rs index e0c6ce7..6f526e7 100644 --- a/src/exercise.rs +++ b/src/exercise.rs @@ -1,7 +1,7 @@ use serde::Deserialize; use std::fmt::{self, Display, Formatter}; -use std::fs::{remove_file}; -use std::path::{PathBuf}; +use std::fs::remove_file; +use std::path::PathBuf; use std::process::{self, Command, Output}; const RUSTC_COLOR_ARGS: &[&str] = &["--color", "always"]; @@ -63,8 +63,8 @@ impl Display for Exercise { #[cfg(test)] mod test { use super::*; - use std::path::Path; use std::fs::File; + use std::path::Path; #[test] fn test_clean() { diff --git a/src/run.rs b/src/run.rs index e108e78..1484351 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,4 +1,4 @@ -use crate::exercise::{Mode, Exercise}; +use crate::exercise::{Exercise, Mode}; use crate::verify::test; use console::{style, Emoji}; use indicatif::ProgressBar; diff --git a/src/verify.rs b/src/verify.rs index c4451b2..4778180 100644 --- a/src/verify.rs +++ b/src/verify.rs @@ -2,7 +2,7 @@ use crate::exercise::{Exercise, Mode}; use console::{style, Emoji}; use indicatif::ProgressBar; -pub fn verify<'a>(start_at: impl IntoIterator) -> Result<(), ()> { +pub fn verify<'a>(start_at: impl IntoIterator) -> Result<(), ()> { for exercise in start_at { match exercise.mode { Mode::Test => test(&exercise)?, From d6d696b66a91d0124b1757c666d94ce018e0c514 Mon Sep 17 00:00:00 2001 From: Eddy Petrisor Date: Wed, 22 May 2019 14:47:49 +0300 Subject: [PATCH 2/4] errorsn.rs: Separate hints from code, so hints are not accidentally seen Signed-off-by: Eddy Petrisor --- exercises/error_handling/errorsn.rs | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/exercises/error_handling/errorsn.rs b/exercises/error_handling/errorsn.rs index 15c6cd5..cd76d5b 100644 --- a/exercises/error_handling/errorsn.rs +++ b/exercises/error_handling/errorsn.rs @@ -108,6 +108,36 @@ impl error::Error for CreationError { } } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + // First hint: To figure out what type should go where the ??? is, take a look // at the test helper function `test_with_str`, since it returns whatever // `read_and_validate` returns and`test_with_str` has its signature fully From a53b3f199f80757a4052e84510afe0aa49ca8e2d Mon Sep 17 00:00:00 2001 From: Eddy Petrisor Date: Wed, 22 May 2019 14:48:19 +0300 Subject: [PATCH 3/4] iterator3.rs: whitespace fixes Signed-off-by: Eddy Petrisor --- exercises/standard_library_types/iterator3.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exercises/standard_library_types/iterator3.rs b/exercises/standard_library_types/iterator3.rs index 1d2e135..083c0af 100644 --- a/exercises/standard_library_types/iterator3.rs +++ b/exercises/standard_library_types/iterator3.rs @@ -114,7 +114,7 @@ mod tests { -// Minor hint: In each of the two cases in the match in main, you can create x with either +// Minor hint: In each of the two cases in the match in main, you can create x with either // a 'turbofish' or by hinting the type of x to the compiler. You may try both. @@ -143,5 +143,5 @@ mod tests { -// Major hint: Have a look at the Iter trait and at the explanation of its collect function. +// Major hint: Have a look at the Iter trait and at the explanation of its collect function. // Especially the part about Result is interesting. From 9aec4abc4d1edb9eacf86c4152675aeddb30694d Mon Sep 17 00:00:00 2001 From: Eddy Petrisor Date: Wed, 22 May 2019 14:48:32 +0300 Subject: [PATCH 4/4] rustfmt the exercises Signed-off-by: Eddy Petrisor --- exercises/error_handling/errors2.rs | 5 +---- exercises/error_handling/errorsn.rs | 9 ++++++--- exercises/error_handling/option1.rs | 5 ++++- exercises/error_handling/result1.rs | 9 ++++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/exercises/error_handling/errors2.rs b/exercises/error_handling/errors2.rs index d97f3b7..8b81207 100644 --- a/exercises/error_handling/errors2.rs +++ b/exercises/error_handling/errors2.rs @@ -32,10 +32,7 @@ mod tests { #[test] fn item_quantity_is_a_valid_number() { - assert_eq!( - total_cost("34"), - Ok(171) - ); + assert_eq!(total_cost("34"), Ok(171)); } #[test] diff --git a/exercises/error_handling/errorsn.rs b/exercises/error_handling/errorsn.rs index cd76d5b..8d39967 100644 --- a/exercises/error_handling/errorsn.rs +++ b/exercises/error_handling/errorsn.rs @@ -65,7 +65,7 @@ fn test_ioerror() { assert_eq!("uh-oh!", read_and_validate(&mut b).unwrap_err().to_string()); } -#[derive(PartialEq,Debug)] +#[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); impl PositiveNonzeroInteger { @@ -83,11 +83,14 @@ impl PositiveNonzeroInteger { #[test] fn test_positive_nonzero_integer_creation() { assert!(PositiveNonzeroInteger::new(10).is_ok()); - assert_eq!(Err(CreationError::Negative), PositiveNonzeroInteger::new(-10)); + assert_eq!( + Err(CreationError::Negative), + PositiveNonzeroInteger::new(-10) + ); assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); } -#[derive(PartialEq,Debug)] +#[derive(PartialEq, Debug)] enum CreationError { Negative, Zero, diff --git a/exercises/error_handling/option1.rs b/exercises/error_handling/option1.rs index 9cf0bc9..13fc720 100644 --- a/exercises/error_handling/option1.rs +++ b/exercises/error_handling/option1.rs @@ -11,7 +11,10 @@ fn main() { println!("The last item in the list is {:?}", last); let second_to_last = list.pop().unwrap(); - println!("The second-to-last item in the list is {:?}", second_to_last); + println!( + "The second-to-last item in the list is {:?}", + second_to_last + ); } diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/result1.rs index 851ab45..f9596e2 100644 --- a/exercises/error_handling/result1.rs +++ b/exercises/error_handling/result1.rs @@ -1,10 +1,10 @@ // result1.rs // Make this test pass! Scroll down for hints :) -#[derive(PartialEq,Debug)] +#[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); -#[derive(PartialEq,Debug)] +#[derive(PartialEq, Debug)] enum CreationError { Negative, Zero, @@ -19,7 +19,10 @@ impl PositiveNonzeroInteger { #[test] fn test_creation() { assert!(PositiveNonzeroInteger::new(10).is_ok()); - assert_eq!(Err(CreationError::Negative), PositiveNonzeroInteger::new(-10)); + assert_eq!( + Err(CreationError::Negative), + PositiveNonzeroInteger::new(-10) + ); assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0)); }