collections
This commit is contained in:
parent
870750151d
commit
2de3ecde06
2 changed files with 12 additions and 5 deletions
|
@ -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);
|
||||
pattern.iter()
|
||||
.map(|x| parse_line(x))
|
||||
.for_each(|res| {
|
||||
if res.is_ok() {
|
||||
res.unwrap().execute(&mut lights);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
Loading…
Reference in a new issue