Compare commits
2 commits
23e4aa8471
...
3a00c4bb09
Author | SHA1 | Date | |
---|---|---|---|
3a00c4bb09 | |||
1f155bd231 |
1 changed files with 9 additions and 8 deletions
|
@ -6,16 +6,17 @@ use std::{
|
||||||
|
|
||||||
type ParseError = Box<dyn std::error::Error>;
|
type ParseError = Box<dyn std::error::Error>;
|
||||||
|
|
||||||
trait Pattern<'a> {
|
pub trait Pattern<'a> {
|
||||||
pub fn execute(&self, values: &'a mut [RawColor]);
|
fn execute(&self, values: &'a mut [RawColor]);
|
||||||
pub fn parse(args: Vec<String>) -> Result<Self, ParseError>;
|
fn parse(args: Vec<String>) -> Result<Self, ParseError> where Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
|
impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
|
||||||
fn try_from(s: Vec<String>) -> Result<Self, ParseError> {
|
type Error = ParseError;
|
||||||
|
fn try_from(s: Vec<String>) -> Result<Self, Self::Error> {
|
||||||
match s[0].as_str() {
|
match s[0].as_str() {
|
||||||
"unit" => Unit::parse(s),
|
"unit" => Ok(Box::new(Unit::parse(s).unwrap()) as Box<dyn Pattern>),
|
||||||
"val" => Value::parse(s),
|
"val" => Ok(Box::new(Value::parse(s).unwrap()) as Box<dyn Pattern>),
|
||||||
_ => Err("No Match".into())
|
_ => Err("No Match".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +88,7 @@ impl<'a> Pattern<'a> for Value {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => Err(e)
|
Err(e) => Err(Box::new(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue