From 7ea486dea68bd9ba27719fbc4a75618ded20c57b Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Tue, 28 Dec 2021 15:05:59 -0500 Subject: [PATCH] ret --- src/main.rs | 4 ++-- src/util/pattern.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index ac3ce0c..e354b99 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,14 +34,14 @@ fn main() { thread::sleep(time::Duration::from_millis(250)); let mut lights = lock.write().unwrap(); let pattern = format_multiline("unit"); - let res: Result>> = pattern.iter() + let res: Result>, ParseError> = pattern.iter() .map(|x: &Vec| parse_line((*x).clone())) .collect(); if res.is_ok() { let v: Vec> = res.unwrap(); for x in 0..v.len() { - v[x].execute(&mut lights); + lights = *(v[x].execute(&mut lights)); } } } diff --git a/src/util/pattern.rs b/src/util/pattern.rs index ce732f1..4f42ff9 100644 --- a/src/util/pattern.rs +++ b/src/util/pattern.rs @@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard; pub type ParseError = Box; pub trait Pattern<'a> { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>); + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>; fn parse(args: Vec) -> Result where Self: Sized; } @@ -25,7 +25,9 @@ impl<'a> TryFrom> for Box> { struct Unit; impl<'a> Pattern<'a> for Unit { - fn execute(&self, _values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {} + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]> { + values + } fn parse(_args: Vec) -> Result { Ok(Unit {}) } @@ -38,7 +40,7 @@ struct Value { } impl<'a> Pattern<'a> for Value { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) { + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]> { for i in 0..crate::LED_SIZE { let mut color: RawColor = (*values)[i]; if self.r.is_some() { @@ -52,6 +54,7 @@ impl<'a> Pattern<'a> for Value { } (*values)[i] = color; } + values } fn parse(args: Vec) -> Result { let param1 = args[1].parse::();