text parsing

This commit is contained in:
jane 2021-12-27 19:00:42 -05:00
parent 782ba40fd3
commit 870750151d
4 changed files with 8 additions and 4 deletions

View File

@ -33,7 +33,7 @@ fn main() {
loop {
thread::sleep(time::Duration::from_millis(250));
let mut lights = lock.write().unwrap();
let pattern = vec!["val".into(), "255".into(), "150".into(), "0".into()];
let pattern = format_multiline("val 255 150 0");
let res = parse_line(pattern);
if res.is_ok() {
res.unwrap().execute(&mut lights);

View File

@ -1,4 +1,3 @@
pub mod lights;
pub mod parser;
pub mod pattern;
pub mod webserver;

View File

View File

@ -97,6 +97,11 @@ impl<'a> Pattern<'a> for Value {
}
pub fn parse_line<'a>(v: Vec<String>) -> Result<Box<dyn Pattern<'a>>, ParseError> {
let res: Result<Box<dyn Pattern>, ParseError> = v.try_into();
res
v.try_into()
}
pub fn format_multiline(input: &str) -> Vec<Vec<String>> {
input.lines()
.map(|x: &str| x.split_whitespace().collect::<Vec<String>>())
.collect()
}