From f09b9ffc154e18dbc1e9cc7fc1df8c918ec768c0 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Wed, 30 Aug 2023 13:07:12 +0200 Subject: [PATCH] Make VirtualLed copyable --- src/output/mod.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/output/mod.rs b/src/output/mod.rs index 42b974a..84f3449 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -257,33 +257,19 @@ impl BlinkingLedsTicker { /// Virtual LED /// /// For displaying virtual LEDs or illuminated buttons in the UI. -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct VirtualLed { pub state: LedState, pub output: LedOutput, } impl VirtualLed { - #[must_use] - pub const fn new() -> Self { - Self { - state: LedState::Off, - output: LedOutput::Off, - } - } -} - -impl Default for VirtualLed { - fn default() -> Self { - Self::new() - } -} + pub const OFF: Self = Self::initial_state(LedState::Off); -impl VirtualLed { - pub fn update_state(&mut self, new_state: LedState) { - let Self { state, output } = self; - *state = new_state; - *output = new_state.initial_output(); + #[must_use] + pub const fn initial_state(state: LedState) -> Self { + let output = state.initial_output(); + Self { state, output } } pub fn update_blinking_output(&mut self, blinking_leds_output: BlinkingLedsOutput) { @@ -291,3 +277,9 @@ impl VirtualLed { *output = state.output(blinking_leds_output); } } + +impl Default for VirtualLed { + fn default() -> Self { + Self::OFF + } +}