mirror of
				https://github.com/sharkdp/bat.git
				synced 2025-11-04 00:51:56 +00:00 
			
		
		
		
	Replace 'is_absolute_path' with map and filter
This commit is contained in:
		
							
								
								
									
										17
									
								
								src/dirs.rs
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								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");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user