]> git.proxmox.com Git - cargo.git/commitdiff
use iterator combinators rather than for loops
authorRalf Jung <post@ralfj.de>
Mon, 18 Sep 2017 09:03:42 +0000 (11:03 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 18 Sep 2017 09:03:42 +0000 (11:03 +0200)
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs

index 88309fdfa66871d443aa6aa2f5b0ec2df21318bb..a8e9ce7048fcacd6b7ccbe9b9639cb00e9fdd914 100644 (file)
@@ -236,12 +236,12 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
                      and the workspace has no members.", ws.current_manifest().display()).into());
     };
 
-    let mut to_builds = Vec::new();
-    for p in specs.iter() {
-        let p = packages.get(p.query(resolve_with_overrides.iter())?)?;
+    let to_builds = specs.iter().map(|p| {
+        let pkgid = p.query(resolve_with_overrides.iter())?;
+        let p = packages.get(pkgid)?;
         p.manifest().print_teapot(ws.config());
-        to_builds.push(p);
-    }
+        Ok(p)
+    }).collect::<CargoResult<Vec<_>>>()?;
 
     let mut general_targets = Vec::new();
     let mut package_targets = Vec::new();
index 0181a0c44f91fee5a621738fd9008c8abc397e4c..2d79cf0630d1c4ccf9e6c513fe42cba7dcfe8040 100644 (file)
@@ -27,10 +27,10 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
                      and the workspace has no members.", ws.current_manifest().display()).into());
     };
 
-    let mut pkgs = Vec::new();
-    for p in specs.iter() {
-        pkgs.push(packages.get(p.query(resolve_with_overrides.iter())?)?);
-    }
+    let pkgs = specs.iter().map(|p| {
+        let pkgid = p.query(resolve_with_overrides.iter())?;
+        packages.get(pkgid)
+    }).collect::<CargoResult<Vec<_>>>()?;
 
     let mut lib_names = HashSet::new();
     let mut bin_names = HashSet::new();