collections

This commit is contained in:
jane 2021-12-27 19:07:48 -05:00
parent 870750151d
commit 2de3ecde06
2 changed files with 12 additions and 5 deletions

View File

@ -34,9 +34,12 @@ fn main() {
thread::sleep(time::Duration::from_millis(250));
let mut lights = lock.write().unwrap();
let pattern = format_multiline("val 255 150 0");
let res = parse_line(pattern);
if res.is_ok() {
res.unwrap().execute(&mut lights);
}
pattern.iter()
.map(|x| parse_line(x))
.for_each(|res| {
if res.is_ok() {
res.unwrap().execute(&mut lights);
}
});
}
}

View File

@ -102,6 +102,10 @@ pub fn parse_line<'a>(v: Vec<String>) -> Result<Box<dyn Pattern<'a>>, ParseError
pub fn format_multiline(input: &str) -> Vec<Vec<String>> {
input.lines()
.map(|x: &str| x.split_whitespace().collect::<Vec<String>>())
.map(|x: &str|
x.split_whitespace()
.map(|y| String::from(y))
.collect::<Vec<String>>()
)
.collect()
}