on master help sign in
Replace 'is_absolute_path' with map and filter
commit6523bbf62f5aaccefb0ba8db462cd5c7c7a3a0c5 authorsharkdp <davidpeter@web.de> dateThu 7 Feb 2019, 21:05 (8 years ago) parent05e2c2c
1 file changed+4−13
src/dirs.rs+4−13
src/dirs.rs+4−13
@@ -18,7 +18,8 @@ impl BatProjectDirs {
1818 fn new() -> Option<BatProjectDirs> {
1919 #[cfg(target_os = "macos")]
2020 let cache_dir_op = env::var_os("XDG_CACHE_HOME")
21− .and_then(is_absolute_path)
21+ .map(PathBuf::from)
22+ .filter(|p| p.is_absolute())
2223 .or_else(|| dirs_rs::home_dir().map(|d| d.join(".cache")));
2324
2425 #[cfg(not(target_os = "macos"))]
@@ -31,7 +32,8 @@ impl BatProjectDirs {
3132
3233 #[cfg(target_os = "macos")]
3334 let config_dir_op = env::var_os("XDG_CONFIG_HOME")
34− .and_then(is_absolute_path)
35+ .map(PathBuf::from)
36+ .filter(|p| p.is_absolute())
3537 .or_else(|| dirs_rs::home_dir().map(|d| d.join(".config")));
3638
3739 #[cfg(not(target_os = "macos"))]
@@ -57,17 +59,6 @@ impl BatProjectDirs {
5759 }
5860}
5961
60−// Returns path if it is an absolute path
61−#[cfg(target_os = "macos")]
62−fn is_absolute_path(path: OsString) -> Option<PathBuf> {
63− let path = PathBuf::from(path);
64− if path.is_absolute() {
65− Some(path)
66− } else {
67− None
68− }
69−}
70−
7162lazy_static! {
7263 pub static ref PROJECT_DIRS: BatProjectDirs =
7364 BatProjectDirs::new().expect("Could not get home directory");