diff options
author | sharkdp <davidpeter@web.de> | 2019-02-07 21:05:59 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2019-02-07 22:19:32 +0100 |
commit | 6523bbf62f5aaccefb0ba8db462cd5c7c7a3a0c5 (patch) | |
tree | 2f7d65b50727a82a91b426b38443822591913c7e /src | |
parent | 05e2c2c66b80806d42c90175e23c833766e3ced5 (diff) |
Replace 'is_absolute_path' with map and filter
Diffstat (limited to 'src')
-rw-r--r-- | src/dirs.rs | 17 |
1 files 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<BatProjectDirs> { #[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<PathBuf> { - 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"); |