From 5e3c166bbfa8bbb0ce5aedfe250d840c5680a4a7 Mon Sep 17 00:00:00 2001 From: Gabriel Dobato Date: Thu, 6 Jun 2024 07:33:26 +0200 Subject: [PATCH] clean up --- examples/usb_led_ctrl.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/examples/usb_led_ctrl.rs b/examples/usb_led_ctrl.rs index afcb2de..39c93d0 100644 --- a/examples/usb_led_ctrl.rs +++ b/examples/usb_led_ctrl.rs @@ -42,7 +42,7 @@ impl Led { *self as u8 } - pub fn from_u8(value: u8) -> Option { + pub const fn from_u8(value: u8) -> Option { match value { 0xAA => Some(Self::Red), 0xBB => Some(Self::Green), @@ -63,7 +63,7 @@ impl Action { *self as u8 } - pub fn from_u8(value: u8) -> Option { + pub const fn from_u8(value: u8) -> Option { match value { 0x01 => Some(Self::On), 0x02 => Some(Self::Off), @@ -147,18 +147,18 @@ mod app { let msg = receiver.recv().await; match msg { Ok(data) => { - if let Some(led) = Led::from_u8(data[0]) { - if let Some(action) = Action::from_u8(data[1]) { - match (led, action) { - (Led::Red, Action::On) => led_red.on(), - (Led::Red, Action::Off) => led_red.off(), - (Led::Green, Action::On) => led_green.on(), - (Led::Green, Action::Off) => led_green.off(), - (Led::Blue, Action::On) => led_blue.on(), - (Led::Blue, Action::Off) => led_blue.off(), - } - debug!("Received: {:?} {:?}", led, action); + if let (Some(led), Some(action)) = + (Led::from_u8(data[0]), Action::from_u8(data[1])) + { + match (led, action) { + (Led::Red, Action::On) => led_red.on(), + (Led::Red, Action::Off) => led_red.off(), + (Led::Green, Action::On) => led_green.on(), + (Led::Green, Action::Off) => led_green.off(), + (Led::Blue, Action::On) => led_blue.on(), + (Led::Blue, Action::Off) => led_blue.off(), } + debug!("Received: {:?} {:?}", led, action); } } Err(_) => {