Skip to content

Commit df83488

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 1c2f16f commit df83488

File tree

4 files changed

+3
-10
lines changed

4 files changed

+3
-10
lines changed

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,3 @@ lto = true
5858
overflow-checks = true
5959
opt-level = "z"
6060
codegen-units = 1
61-
62-
[lints.clippy]
63-
# This is necessary because the `.is_multiple_of()` function that this lint
64-
# suggests is not yet stabilized in the rust version used in Yocto walnascar
65-
# (1.84.1).
66-
# TODO: remove this when updating to a newer yocto release.
67-
manual_is_multiple_of = "allow"

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)