From dee29fa198034ba2eca44029fe3195650a4964a0 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Sat, 19 Jun 2021 09:10:18 +0100 Subject: [PATCH] refactor closures and iterators --- backend/src/daemon/dummy.rs | 3 +-- backend/src/key.rs | 7 ++++--- backend/src/keymap.rs | 2 +- backend/src/layout/mod.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/daemon/dummy.rs b/backend/src/daemon/dummy.rs index d889b98c..48f884d1 100644 --- a/backend/src/daemon/dummy.rs +++ b/backend/src/daemon/dummy.rs @@ -25,8 +25,7 @@ impl BoardDummy { .leds .values() .flatten() - .find(|i| **i == index) - .is_some() + .any(|i| *i == index) } } } diff --git a/backend/src/key.rs b/backend/src/key.rs index dcd2a9a7..ba2979ec 100644 --- a/backend/src/key.rs +++ b/backend/src/key.rs @@ -60,11 +60,12 @@ impl Key { .layout() .leds .get(logical_name.as_str()) - .map_or(Vec::new(), |x| x.clone()); + .cloned() + .unwrap_or_default(); debug!(" LEDs: {:?}", leds); let mut led_name = String::new(); - for led in leds.iter() { + for led in &leds { if !led_name.is_empty() { led_name.push_str(", "); } @@ -92,7 +93,7 @@ impl Key { } let mut led_color = None; - if board.layout().meta.has_mode && leds.len() > 0 { + if board.layout().meta.has_mode && !leds.is_empty() { match daemon.color(board.board(), leds[0]) { Ok((0, 0, 0)) => {} Ok((r, g, b)) => led_color = Some(Rgb::new(r, g, b).to_hs_lossy()), diff --git a/backend/src/keymap.rs b/backend/src/keymap.rs index 3c308ff1..9ce0b8be 100644 --- a/backend/src/keymap.rs +++ b/backend/src/keymap.rs @@ -26,7 +26,7 @@ mod hs_map_serde { ) -> Result { let map = map .iter() - .map(|(k, hs)| (k, hs.map(|hs| hs.to_ints()))) + .map(|(k, hs)| (k, hs.map(Hs::to_ints))) .collect::>(); map.serialize(serializer) } diff --git a/backend/src/layout/mod.rs b/backend/src/layout/mod.rs index 328f4b2c..b4aed56e 100644 --- a/backend/src/layout/mod.rs +++ b/backend/src/layout/mod.rs @@ -214,7 +214,7 @@ mod tests { .physical .keys .iter() - .map(|i| i.logical_name()) + .map(PhysicalLayoutKey::logical_name) .collect::>(); let logical_in_layout = layout.layout.keys().cloned().collect::>(); let logical_in_leds = layout.layout.keys().cloned().collect::>();