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 = {
["python", "python3"]
.iter()
.map(|bin| (bin, Command::new(bin).arg("--version").output()))
.filter(|(_, r)| r.is_ok())
.map(|(bin, r)| (bin, r.unwrap()))
.find(|bin| {
if let Ok(out) = Command::new(bin).arg("--version").output() {
// begin with `Python 3.X.X :: additional info`
.find(|(_, r)| r.stdout.starts_with(b"Python 3") || r.stderr.starts_with(b"Python 3"))
.map(|(bin, _)| bin)
out.stdout.starts_with(b"Python 3") || out.stderr.starts_with(b"Python 3")
} else {
false
}
})
.expect("Python 3.x interpreter not found")
};
}