From a0e336bc02022197a7538adca4031952beb176d3 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Sun, 18 Mar 2018 18:41:46 -0400 Subject: [PATCH] Clean up result partition --- ofborg/src/lib.rs | 13 +++++++++++++ ofborg/src/nix.rs | 15 ++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ofborg/src/lib.rs b/ofborg/src/lib.rs index da6fd36..1d8a20c 100644 --- a/ofborg/src/lib.rs +++ b/ofborg/src/lib.rs @@ -70,6 +70,19 @@ pub mod ofborg { pub use easyamqp; pub const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + + pub fn partition_result(results: Vec>) -> (Vec, Vec) { + let mut ok = Vec::new(); + let mut err = Vec::new(); + for result in results.into_iter() { + match result { + Ok(x) => { ok.push(x); } + Err(x) => { err.push(x); } + } + } + + (ok, err) + } } pub fn setup_log() { diff --git a/ofborg/src/nix.rs b/ofborg/src/nix.rs index 4f2d8cb..91b78a2 100644 --- a/ofborg/src/nix.rs +++ b/ofborg/src/nix.rs @@ -8,6 +8,7 @@ use std::process::{Command, Stdio}; use tempfile::tempfile; use std::io::BufReader; use std::io::BufRead; +use ofborg::partition_result; #[derive(Clone, Debug)] pub enum Operation { @@ -120,19 +121,7 @@ impl Nix { ) .collect(); - let (ok, err): ( - Vec)>>, - Vec)>>) = attr_instantiations - .into_iter() - .partition(|x| x.is_ok()); - - let ok_ret: Vec = ok.into_iter().map(|x| x.unwrap()).collect(); - let err_ret: Vec<(String, Vec)> = err.into_iter().map(|x| x.unwrap_err()).collect(); - - return ( - ok_ret, - err_ret - ) + partition_result(attr_instantiations) } pub fn safely_instantiate_attrs(