From 12819f0eb8fdd128e99f3be107f8d996803ebd02 Mon Sep 17 00:00:00 2001 From: Adam Wick Date: Thu, 3 Dec 2020 07:49:59 -0800 Subject: [PATCH] Some formatting cleanups. --- src/bin/password_check.rs | 17 +++++++++++++---- src/errors.rs | 8 +++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/bin/password_check.rs b/src/bin/password_check.rs index 5e67626..23fcdb1 100644 --- a/src/bin/password_check.rs +++ b/src/bin/password_check.rs @@ -38,7 +38,11 @@ impl FromStr for PasswordData { impl PasswordData { fn is_valid_interpretation1(&self) -> bool { - let count = self.password.chars().filter(|x| *x == self.character).count(); + let count = self + .password + .chars() + .filter(|x| *x == self.character) + .count(); (count >= self.first_number) && (count <= self.second_number) } @@ -60,7 +64,6 @@ impl PasswordData { } } - fn real_main() -> Result<(), TopLevelError> { let mut good_items_interpretation1 = 0u64; let mut good_items_interpretation2 = 0u64; @@ -83,8 +86,14 @@ fn real_main() -> Result<(), TopLevelError> { } } - println!("# of good passwords, according to interpretation #1: {}", good_items_interpretation1); - println!("# of good passwords, according to interpretation #2: {}", good_items_interpretation2); + println!( + "# of good passwords, according to interpretation #1: {}", + good_items_interpretation1 + ); + println!( + "# of good passwords, according to interpretation #2: {}", + good_items_interpretation2 + ); Ok(()) } diff --git a/src/errors.rs b/src/errors.rs index 21fd292..aa2e2b9 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -35,17 +35,19 @@ convert_error!(io::Error, TopLevelError, IOError); pub enum PasswordParseError { StringToIntError(ParseIntError), - NomError(nom::Err<()>) + NomError(nom::Err<()>), } impl fmt::Display for PasswordParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { PasswordParseError::NomError(e) => write!(f, "Parse error: {}", e), - PasswordParseError::StringToIntError(e) => write!(f, "Error converting string to integer: {}", e), + PasswordParseError::StringToIntError(e) => { + write!(f, "Error converting string to integer: {}", e) + } } } } convert_error!(ParseIntError, PasswordParseError, StringToIntError); -convert_error!(nom::Err<()>, PasswordParseError, NomError); \ No newline at end of file +convert_error!(nom::Err<()>, PasswordParseError, NomError);