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