complicated method chain

This commit is contained in:
namuyan 2019-10-12 17:00:19 +09:00
parent 4b1c48831a
commit 91b3231038
1 changed files with 8 additions and 6 deletions

View File

@ -27,12 +27,14 @@ lazy_static! {
static ref PYTHON_INTERPRETER: &'static str = { static ref PYTHON_INTERPRETER: &'static str = {
["python", "python3"] ["python", "python3"]
.iter() .iter()
.map(|bin| (bin, Command::new(bin).arg("--version").output())) .find(|bin| {
.filter(|(_, r)| r.is_ok()) if let Ok(out) = Command::new(bin).arg("--version").output() {
.map(|(bin, r)| (bin, r.unwrap()))
// begin with `Python 3.X.X :: additional info` // begin with `Python 3.X.X :: additional info`
.find(|(_, r)| r.stdout.starts_with(b"Python 3") || r.stderr.starts_with(b"Python 3")) out.stdout.starts_with(b"Python 3") || out.stderr.starts_with(b"Python 3")
.map(|(bin, _)| bin) } else {
false
}
})
.expect("Python 3.x interpreter not found") .expect("Python 3.x interpreter not found")
}; };
} }