replace map flatten with and_then

This commit is contained in:
2024-10-04 17:34:23 +02:00
parent 82d4c4c04f
commit 41a17c8f57

View File

@@ -42,14 +42,13 @@ pub fn pb_style_download(pb: &ProgressBar, state: bool) {
#[cfg(unix)] #[cfg(unix)]
pub fn is_program_in_path(program: &str) -> bool { pub fn is_program_in_path(program: &str) -> bool {
std::env::var_os("PATH") std::env::var_os("PATH")
.map(|paths| { .and_then(|paths| {
paths.to_str().map(|paths| { paths.to_str().map(|paths| {
paths paths
.split(':') .split(':')
.any(|dir| fs::metadata(format!("{}/{}", dir, program)).is_ok()) .any(|dir| fs::metadata(format!("{}/{}", dir, program)).is_ok())
}) })
}) })
.flatten()
.unwrap_or(false) .unwrap_or(false)
} }