Revert "ret"

This reverts commit 7ea486dea6.
This commit is contained in:
jane 2021-12-28 15:12:33 -05:00
parent 7ea486dea6
commit dafac3d248
2 changed files with 5 additions and 8 deletions

View File

@ -34,14 +34,14 @@ fn main() {
thread::sleep(time::Duration::from_millis(250)); thread::sleep(time::Duration::from_millis(250));
let mut lights = lock.write().unwrap(); let mut lights = lock.write().unwrap();
let pattern = format_multiline("unit"); let pattern = format_multiline("unit");
let res: Result<Vec<Box<dyn Pattern>>, ParseError> = pattern.iter() let res: Result<Vec<Box<dyn Pattern>>> = pattern.iter()
.map(|x: &Vec<String>| parse_line((*x).clone())) .map(|x: &Vec<String>| parse_line((*x).clone()))
.collect(); .collect();
if res.is_ok() { if res.is_ok() {
let v: Vec<Box<dyn Pattern>> = res.unwrap(); let v: Vec<Box<dyn Pattern>> = res.unwrap();
for x in 0..v.len() { for x in 0..v.len() {
lights = *(v[x].execute(&mut lights)); v[x].execute(&mut lights);
} }
} }
} }

View File

@ -8,7 +8,7 @@ use std::sync::RwLockWriteGuard;
pub type ParseError = Box<dyn std::error::Error>; pub type ParseError = Box<dyn std::error::Error>;
pub trait Pattern<'a> { pub trait Pattern<'a> {
fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>; 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,9 +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; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]> { fn execute(&self, _values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {}
values
}
fn parse(_args: Vec<String>) -> Result<Self, ParseError> { fn parse(_args: Vec<String>) -> Result<Self, ParseError> {
Ok(Unit {}) Ok(Unit {})
} }
@ -40,7 +38,7 @@ struct Value {
} }
impl<'a> Pattern<'a> for Value { impl<'a> Pattern<'a> for Value {
fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) -> &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]> { fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor; crate::LED_SIZE]>) {
for i in 0..crate::LED_SIZE { for i in 0..crate::LED_SIZE {
let mut color: RawColor = (*values)[i]; let mut color: RawColor = (*values)[i];
if self.r.is_some() { if self.r.is_some() {
@ -54,7 +52,6 @@ impl<'a> Pattern<'a> for Value {
} }
(*values)[i] = color; (*values)[i] = color;
} }
values
} }
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>();