From b96f0d80dbe9f655d4b9cf001670f4f6ed7ffbd2 Mon Sep 17 00:00:00 2001 From: Jane Petrovna Date: Sun, 26 Dec 2021 21:36:05 -0500 Subject: [PATCH] deref syntax? --- src/util/pattern.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/util/pattern.rs b/src/util/pattern.rs index ec06c1d..877e08d 100644 --- a/src/util/pattern.rs +++ b/src/util/pattern.rs @@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard; type ParseError = Box; pub trait Pattern<'a> { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>); + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>); fn parse(args: Vec) -> Result where Self: Sized; } @@ -25,7 +25,7 @@ impl<'a> TryFrom> for Box> { struct Unit; impl<'a> Pattern<'a> for Unit { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>) {} + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {} fn parse(args: Vec) -> Result { Ok(Unit {}) } @@ -38,9 +38,10 @@ struct Value { } impl<'a> Pattern<'a> for Value { - fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>) { + fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) { + let mut v = *values; for i in 0..crate::LED_SIZE { - let color: RawColor = *values[i]; + let mut color: RawColor = v[i]; if self.r.is_some() { color[0] = self.r.unwrap(); } @@ -50,8 +51,9 @@ impl<'a> Pattern<'a> for Value { if self.b.is_some() { color[0] = self.b.unwrap(); } - *values[i] = color; + v[i] = color; } + *values = v; } fn parse(args: Vec) -> Result { let param1 = args[1].parse::(); @@ -95,7 +97,7 @@ impl<'a> Pattern<'a> for Value { } } -pub fn parse_line(v: Vec) -> Result>, ParseError> { +pub fn parse_line(v: Vec) -> Result>, ParseError> { let res: Result, ParseError> = v.try_into(); res }