Skip to content

Commit 59e8043

Browse files
committed
tacd: replace instances of x % N == 0 with x.is_multiple_of(N)
This is inspired by a recently added clippy lint: error: manual implementation of `.is_multiple_of()` --> src/dut_power.rs:248:16 | 248 | if N % 2 == 0 { | ^^^^^^^^^^ help: replace with: `N.is_multiple_of(2)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of = note: `-D clippy::manual-is-multiple-of` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::manual_is_multiple_of)]` error: manual implementation of `.is_multiple_of()` --> src/ui/screens/diagnostics.rs:256:26 | 256 | let on = self.led_cycle_state % 2 != 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `!self.led_cycle_state.is_multiple_of(2)` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_multiple_of Signed-off-by: Leonard Göhrs <[email protected]>
1 parent 71aae7a commit 59e8043

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

src/dut_power.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<const N: usize> MedianFilter<N> {
245245
sorted
246246
};
247247

248-
if N % 2 == 0 {
248+
if N.is_multiple_of(2) {
249249
Some((sorted[N / 2 - 1] + sorted[N / 2]) / 2.0)
250250
} else {
251251
Some(sorted[N / 2])

src/ui/screens/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl ActiveScreen for Active {
253253
InputEvent::ToggleAction(_) => {
254254
self.led_cycle_state = self.led_cycle_state.wrapping_add(1);
255255

256-
let on = self.led_cycle_state % 2 != 0;
256+
let on = !self.led_cycle_state.is_multiple_of(2);
257257
let led_brightness = if on { 1.0 } else { 0.0 };
258258
let backlight_brightness = if on { 1.0 } else { 0.1 };
259259
let status_color = match self.led_cycle_state % 8 {

src/ui/screens/locator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl ActivatableScreen for LocatorScreen {
120120
display,
121121
Box::new(move |now, target| {
122122
// Blink a bar below the hostname at 2Hz
123-
let on = (now.duration_since(start).as_millis() / 500) % 2 == 0;
123+
let on = (now.duration_since(start).as_millis() / 500).is_multiple_of(2);
124124

125125
if on {
126126
let line = Line::new(Point::new(40, 135), Point::new(200, 135))

0 commit comments

Comments
 (0)