rust: Use flat_map for splitting package whitespace

This is mostly for fun, though I do like the final result as well.

Closes: #1390
Approved by: cgwalters
This commit is contained in:
Jonathan Lebon 2018-06-05 15:51:56 -04:00 committed by Atomic Bot
parent 60d49c3413
commit 98ed545e1e

View File

@ -81,13 +81,7 @@ fn treefile_read_impl(filename: &Path, output: fs::File) -> io::Result<()> {
}
fn whitespace_split_packages(pkgs: &[String]) -> Vec<String> {
let mut ret = Vec::with_capacity(pkgs.len());
for pkg in pkgs {
for pkg_item in pkg.split_whitespace() {
ret.push(pkg_item.into());
}
}
ret
pkgs.iter().flat_map(|pkg| pkg.split_whitespace().map(String::from)).collect()
}
#[derive(Serialize, Deserialize, Debug)]