Clean up result partition

This commit is contained in:
Graham Christensen 2018-03-18 18:41:46 -04:00
parent ec75dba4da
commit a0e336bc02
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
2 changed files with 15 additions and 13 deletions

View file

@ -70,6 +70,19 @@ pub mod ofborg {
pub use easyamqp;
pub const VERSION: &'static str = env!("CARGO_PKG_VERSION");
pub fn partition_result<A,B>(results: Vec<Result<A,B>>) -> (Vec<A>, Vec<B>) {
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() {

View file

@ -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<Result<String, (String, Vec<String>)>>,
Vec<Result<String, (String, Vec<String>)>>) = attr_instantiations
.into_iter()
.partition(|x| x.is_ok());
let ok_ret: Vec<String> = ok.into_iter().map(|x| x.unwrap()).collect();
let err_ret: Vec<(String, Vec<String>)> = err.into_iter().map(|x| x.unwrap_err()).collect();
return (
ok_ret,
err_ret
)
partition_result(attr_instantiations)
}
pub fn safely_instantiate_attrs(