Compare commits
1 commit
6508fe03e2
...
ac08d4d3a4
Author | SHA1 | Date | |
---|---|---|---|
ac08d4d3a4 |
1 changed files with 4 additions and 4 deletions
|
@ -11,7 +11,7 @@ trait Pattern<'a> {
|
||||||
fn parse(args: Vec<String>) -> Result<Self, ParseError>;
|
fn parse(args: Vec<String>) -> Result<Self, ParseError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
|
impl TryFrom<Vec<String>> for Box<dyn Pattern> {
|
||||||
fn try_from(s: Vec<String>) -> Result<Self, ParseError> {
|
fn try_from(s: Vec<String>) -> Result<Self, ParseError> {
|
||||||
match s[0].as_str() {
|
match s[0].as_str() {
|
||||||
"unit" => Unit::parse(s),
|
"unit" => Unit::parse(s),
|
||||||
|
@ -22,7 +22,7 @@ impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Unit;
|
struct Unit;
|
||||||
impl<'a> Pattern<'a> for Unit {
|
impl<'a> Pattern for Unit<'a> {
|
||||||
fn execute(&self, values: &'a mut [RawColor]) {}
|
fn execute(&self, values: &'a mut [RawColor]) {}
|
||||||
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
fn parse(args: Vec<String>) -> Result<Self, ParseError> {
|
||||||
Ok(Unit {})
|
Ok(Unit {})
|
||||||
|
@ -35,7 +35,7 @@ struct Value {
|
||||||
b: Option<u8>
|
b: Option<u8>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Pattern<'a> for Value {
|
impl<'a> Pattern for Value<'a> {
|
||||||
fn execute(&self, values: &'a mut [RawColor]) {
|
fn execute(&self, values: &'a mut [RawColor]) {
|
||||||
for i in 0..crate::LED_SIZE {
|
for i in 0..crate::LED_SIZE {
|
||||||
let color: RawColor = values[i];
|
let color: RawColor = values[i];
|
||||||
|
@ -93,7 +93,7 @@ impl<'a> Pattern<'a> for Value {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_line(v: Vec<String>) -> Result<Box<dyn Pattern<'static>>, ParseError> {
|
pub fn parse_line(v: Vec<String>) -> Result<Box<dyn Pattern>, ParseError> {
|
||||||
let res: Result<Box<dyn Pattern>, ParseError> = v.try_into();
|
let res: Result<Box<dyn Pattern>, ParseError> = v.try_into();
|
||||||
res
|
res
|
||||||
}
|
}
|
Loading…
Reference in a new issue