Compare commits

...

1 commit

Author SHA1 Message Date
cedae98d0f deref syntax? 2021-12-26 21:36:05 -05:00

View file

@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard;
type ParseError = Box<dyn std::error::Error>;
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<String>) -> Result<Self, ParseError> where Self: Sized;
}
@ -25,7 +25,7 @@ impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
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<String>) -> Result<Self, ParseError> {
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 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<String>) -> Result<Self, ParseError> {
let param1 = args[1].parse::<u8>();