From e4f200a85a9dd495b412f72761f6ef3b99e4e1ed Mon Sep 17 00:00:00 2001 From: David Cosby Date: Fri, 27 Sep 2024 18:09:19 -0600 Subject: [PATCH] exposed .leds() in driver, pass by reference instead of clone --- src/driver/mod.rs | 12 ++++++++++-- src/sled/meta.rs | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/driver/mod.rs b/src/driver/mod.rs index a43e20d..16d948b 100644 --- a/src/driver/mod.rs +++ b/src/driver/mod.rs @@ -1,6 +1,6 @@ use crate::{ color::{Rgb, Srgb}, - Sled, SledError, Vec2, + Led, Sled, SledError, Vec2, }; use std::time::{Duration, Instant}; @@ -118,7 +118,15 @@ impl Driver { self.sled.take().unwrap() } - pub fn colors(&self) -> impl Iterator + '_ { + pub fn leds(&self) -> impl Iterator { + if let Some(sled) = &self.sled { + sled.leds() + } else { + panic!("Driver has no Sled assigned!") + } + } + + pub fn colors(&self) -> impl Iterator + '_ { if let Some(sled) = &self.sled { sled.colors() } else { diff --git a/src/sled/meta.rs b/src/sled/meta.rs index fc8f463..6d7fa05 100644 --- a/src/sled/meta.rs +++ b/src/sled/meta.rs @@ -119,8 +119,8 @@ impl Sled { /// /*- snip -*/ /// } /// ``` - pub fn colors(&self) -> impl Iterator + '_ { - self.leds.iter().map(|led| led.color) + pub fn colors(&self) -> impl Iterator + '_ { + self.leds.iter().map(|led| &led.color) } /// Returns an Iterator over the RGB colors for each [LED](Led) in the system.