From 6523bbf62f5aaccefb0ba8db462cd5c7c7a3a0c5 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Thu, 7 Feb 2019 21:05:59 +0100 Subject: [PATCH] Replace 'is_absolute_path' with map and filter --- src/dirs.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/dirs.rs b/src/dirs.rs index 7895c523..29e79b2e 100644 --- a/src/dirs.rs +++ b/src/dirs.rs @@ -18,7 +18,8 @@ impl BatProjectDirs { fn new() -> Option { #[cfg(target_os = "macos")] let cache_dir_op = env::var_os("XDG_CACHE_HOME") - .and_then(is_absolute_path) + .map(PathBuf::from) + .filter(|p| p.is_absolute()) .or_else(|| dirs_rs::home_dir().map(|d| d.join(".cache"))); #[cfg(not(target_os = "macos"))] @@ -31,7 +32,8 @@ impl BatProjectDirs { #[cfg(target_os = "macos")] let config_dir_op = env::var_os("XDG_CONFIG_HOME") - .and_then(is_absolute_path) + .map(PathBuf::from) + .filter(|p| p.is_absolute()) .or_else(|| dirs_rs::home_dir().map(|d| d.join(".config"))); #[cfg(not(target_os = "macos"))] @@ -57,17 +59,6 @@ impl BatProjectDirs { } } -// Returns path if it is an absolute path -#[cfg(target_os = "macos")] -fn is_absolute_path(path: OsString) -> Option { - let path = PathBuf::from(path); - if path.is_absolute() { - Some(path) - } else { - None - } -} - lazy_static! { pub static ref PROJECT_DIRS: BatProjectDirs = BatProjectDirs::new().expect("Could not get home directory");