rw lock write

This commit is contained in:
jane 2021-12-26 21:32:42 -05:00
parent 3a00c4bb09
commit 455fff23cb

View file

@ -3,11 +3,12 @@ use std::{
vec::Vec,
string::String
};
use std::sync::RwLockWriteGuard;
type ParseError = Box<dyn std::error::Error>;
pub trait Pattern<'a> {
fn execute(&self, values: &'a mut [RawColor]);
fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>);
fn parse(args: Vec<String>) -> Result<Self, ParseError> where Self: Sized;
}
@ -24,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 [RawColor]) {}
fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>) {}
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
Ok(Unit {})
}
@ -37,9 +38,9 @@ struct Value {
}
impl<'a> Pattern<'a> for Value {
fn execute(&self, values: &'a mut [RawColor]) {
fn execute(&self, values: &'a mut RwLockWriteGuard<'_, [RawColor]>) {
for i in 0..crate::LED_SIZE {
let color: RawColor = values[i];
let color: RawColor = *values[i];
if self.r.is_some() {
color[0] = self.r.unwrap();
}
@ -49,7 +50,7 @@ impl<'a> Pattern<'a> for Value {
if self.b.is_some() {
color[0] = self.b.unwrap();
}
values[i] = color;
*values[i] = color;
}
}
fn parse(args: Vec<String>) -> Result<Self, ParseError> {