diff --git a/src/format.rs b/src/format.rs index b9e6f04..4131c2b 100644 --- a/src/format.rs +++ b/src/format.rs @@ -205,7 +205,6 @@ impl Pattern { } /// Ensure that the indentation returns to zero at the end of the file -fn indents_return_to_zero(state: &State) -> bool { - #![allow(clippy::missing_const_for_fn)] +const fn indents_return_to_zero(state: &State) -> bool { state.indent.actual == 0 } diff --git a/src/indent.rs b/src/indent.rs index 608bf86..ac531c8 100644 --- a/src/indent.rs +++ b/src/indent.rs @@ -55,10 +55,10 @@ fn get_diff(line: &str, pattern: &Pattern) -> i8 { }; // indent for delimiters - diff += i8::try_from(line.chars().filter(|x| OPENS.contains(x)).count()) - .unwrap(); - diff -= i8::try_from(line.chars().filter(|x| CLOSES.contains(x)).count()) - .unwrap(); + diff += line + .chars() + .map(|x| i8::from(OPENS.contains(&x)) - i8::from(CLOSES.contains(&x))) + .sum::(); diff }