Compare commits

..

No commits in common. "3a00c4bb09dbefb9b2644002bb8c622f2e00a3b0" and "23e4aa8471484b7f26cb06a7b1f63d5ae1aa9af9" have entirely different histories.

View file

@ -6,17 +6,16 @@ use std::{
type ParseError = Box<dyn std::error::Error>;
pub trait Pattern<'a> {
fn execute(&self, values: &'a mut [RawColor]);
fn parse(args: Vec<String>) -> Result<Self, ParseError> where Self: Sized;
trait Pattern<'a> {
pub fn execute(&self, values: &'a mut [RawColor]);
pub fn parse(args: Vec<String>) -> Result<Self, ParseError>;
}
impl<'a> TryFrom<Vec<String>> for Box<dyn Pattern<'a>> {
type Error = ParseError;
fn try_from(s: Vec<String>) -> Result<Self, Self::Error> {
fn try_from(s: Vec<String>) -> Result<Self, ParseError> {
match s[0].as_str() {
"unit" => Ok(Box::new(Unit::parse(s).unwrap()) as Box<dyn Pattern>),
"val" => Ok(Box::new(Value::parse(s).unwrap()) as Box<dyn Pattern>),
"unit" => Unit::parse(s),
"val" => Value::parse(s),
_ => Err("No Match".into())
}
}
@ -88,7 +87,7 @@ impl<'a> Pattern<'a> for Value {
})
}
},
Err(e) => Err(Box::new(e))
Err(e) => Err(e)
}
}
}
@ -97,4 +96,4 @@ impl<'a> Pattern<'a> for Value {
pub fn parse_line(v: Vec<String>) -> Result<Box<dyn Pattern<'static>>, ParseError> {
let res: Result<Box<dyn Pattern>, ParseError> = v.try_into();
res
}
}