Compare commits
1 commit
b96f0d80db
...
cedae98d0f
Author | SHA1 | Date | |
---|---|---|---|
cedae98d0f |
1 changed files with 7 additions and 5 deletions
|
@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard;
|
||||||
type ParseError = Box<dyn std::error::Error>;
|
type ParseError = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
pub trait Pattern<'a> {
|
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;
|
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;
|
struct Unit;
|
||||||
impl<'a> Pattern<'a> for 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> {
|
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
||||||
Ok(Unit {})
|
Ok(Unit {})
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,10 @@ struct Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Pattern<'a> for 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 {
|
for i in 0..crate::LED_SIZE {
|
||||||
let color: RawColor = *values[i];
|
let color: RawColor = v[i];
|
||||||
if self.r.is_some() {
|
if self.r.is_some() {
|
||||||
color[0] = self.r.unwrap();
|
color[0] = self.r.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -50,8 +51,9 @@ impl<'a> Pattern<'a> for Value {
|
||||||
if self.b.is_some() {
|
if self.b.is_some() {
|
||||||
color[0] = self.b.unwrap();
|
color[0] = self.b.unwrap();
|
||||||
}
|
}
|
||||||
*values[i] = color;
|
v[i] = color;
|
||||||
}
|
}
|
||||||
|
*values = v;
|
||||||
}
|
}
|
||||||
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
||||||
let param1 = args[1].parse::<u8>();
|
let param1 = args[1].parse::<u8>();
|
||||||
|
|
Loading…
Reference in a new issue