From d12dce373c132aeb838b3d7090940f1d65bc0aed Mon Sep 17 00:00:00 2001 From: Serge Latyntcev Date: Sun, 11 Feb 2024 15:05:41 +1300 Subject: [PATCH] chore(clippy): fix clippy warnings --- .github/workflows/main.yml | 2 +- src/decimal/mod.rs | 42 ++++++++++++++----------------- src/fraction/display.rs | 45 ++++++++++++++++++++-------------- src/fraction/unicode_str_io.rs | 2 +- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54edaaba..3ba85cdf 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -68,4 +68,4 @@ jobs: uses: actions-rs/cargo@v1 with: command: clippy - args: --all-features -- -D warnings \ No newline at end of file + args: --all-features -- -D warnings -A deprecated \ No newline at end of file diff --git a/src/decimal/mod.rs b/src/decimal/mod.rs index 9961ba30..42f6e22f 100644 --- a/src/decimal/mod.rs +++ b/src/decimal/mod.rs @@ -407,38 +407,32 @@ where let mut precision: usize = 0; loop { - s_state = match division::divide_rem_resume( - s_state.take().unwrap(), - |s, d| { + s_state = if let Ok(s) = + division::divide_rem_resume(s_state.take().unwrap(), |s, d| { s_digit = d; Ok(Err(s)) - }, - ) { - Ok(s) => { - if s.remainder.is_zero() { - None - } else { - Some(s) - } + }) { + if s.remainder.is_zero() { + None + } else { + Some(s) } - Err(_) => return false, + } else { + return false; }; - o_state = match division::divide_rem_resume( - o_state.take().unwrap(), - |s, d| { + o_state = if let Ok(s) = + division::divide_rem_resume(o_state.take().unwrap(), |s, d| { o_digit = d; Ok(Err(s)) - }, - ) { - Ok(s) => { - if s.remainder.is_zero() { - None - } else { - Some(s) - } + }) { + if s.remainder.is_zero() { + None + } else { + Some(s) } - Err(_) => return false, + } else { + return false; }; if s_digit != o_digit { diff --git a/src/fraction/display.rs b/src/fraction/display.rs index 4d3cb4bb..ce4a6407 100644 --- a/src/fraction/display.rs +++ b/src/fraction/display.rs @@ -299,39 +299,46 @@ where let mut length = 0; if let Some(precision) = format.precision() { - match division::divide_to_callback( + let callback = |digit| { + length += 1; + division::write_digit(buffer, digit) + }; + + if division::divide_to_callback( numer, denom, *precision, format.alternate(), - |digit| { - length += 1; - division::write_digit(buffer, digit) - }, - ) { - Ok(_) => Ok(()), - Err(_) => Err(fmt::Error), - }?; + callback, + ) + .is_err() + { + return Err(fmt::Error); + } } else { - match division::divide_to_callback(numer, T::one(), 0, false, |digit| { + let callback = |digit| { length += 1; division::write_digit(buffer, digit) - }) { - Ok(_) => Ok(()), - Err(_) => Err(fmt::Error), - }?; + }; + + if division::divide_to_callback(numer, T::one(), 0, false, callback).is_err() { + return Err(fmt::Error); + } if !ratio.numer().is_zero() && !ratio.denom().is_one() { length += 1; buffer.write_char('/')?; - match division::divide_to_callback(denom, T::one(), 0, false, |digit| { + let callback = |digit| { length += 1; division::write_digit(buffer, digit) - }) { - Ok(_) => Ok(()), - Err(_) => Err(fmt::Error), - }?; + }; + + if division::divide_to_callback(denom, T::one(), 0, false, callback) + .is_err() + { + return Err(fmt::Error); + }; } } diff --git a/src/fraction/unicode_str_io.rs b/src/fraction/unicode_str_io.rs index c090d52d..f8506bcb 100644 --- a/src/fraction/unicode_str_io.rs +++ b/src/fraction/unicode_str_io.rs @@ -551,7 +551,7 @@ mod tests { #[test] fn test_from_fail() { // TODO: "nanBOGUS" and "∞BOGUS" will parse. - // Either make that everything with BOGUS + // Either make that everything with BOGUS // after will parse, or make ^those fail. let test_vec = vec![ "asdf",