Debian Codegraph @

src/utils/bat/dirs.rs

raw symbols SCIP
1 // Based on code from https://github.com/sharkdp/bat e981e974076a926a38f124b7d8746de2ca5f0a28
2 // See src/utils/bat/LICENSE
3
4 use lazy_staticrust-analyzer cargo lazy_static 1.4.0 crate/::lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#};
6
7 #[cfg(target_os = "macos")]
8 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/;
9
10 /// Wrapper for 'dirs' that treats MacOS more like Linux, by following the XDG specification.
11 /// This means that the `XDG_CACHE_HOME` and `XDG_CONFIG_HOME` environment variables are
12 /// checked first. The fallback directories are `~/.cache/bat` and `~/.config/bat`, respectively.
13 pub struct BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs# {
14 cache_dirrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs#cache_dir.: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#,
15 }
16
17 impl BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs# {
18 fn newrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/impl#[BatProjectDirs]new().() -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs#> {
19 #[cfg(target_os = "macos")]
20 let cache_dir_op = env::var_os("XDG_CACHE_HOME")
21 .map(PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::from)
22 .filter(|p| p.is_absolute())
23 .or_else(|| dirsrust-analyzer cargo dirs 6.0.0 crate/::home_dirrust-analyzer cargo dirs 6.0.0 home_dir().().map(|d| d.join(".cache")));
24
25 #[cfg(not(target_os = "macos"))]
26 let cache_dir_op = dirsrust-analyzer cargo dirs 6.0.0 crate/::cache_dirrust-analyzer cargo dirs 6.0.0 cache_dir().();
27
28 let cache_dir = cache_dir_op.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|d| d.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("bat"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
29
30 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs# { cache_dirrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs#cache_dir. })
31 }
32
33 pub fn cache_dirrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/impl#[BatProjectDirs]cache_dir().(&self) -> &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path# {
34 &self.cache_dirrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs#cache_dir.
35 }
36 }
37
38 lazy_staticrust-analyzer cargo lazy_static 1.4.0 lazy_static!! {
39 pub static ref PROJECT_DIRSrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/PROJECT_DIRS#: BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs# =
40 BatProjectDirsrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/BatProjectDirs#::newrust-analyzer cargo git-delta 0.19.2 utils/bat/dirs/impl#[BatProjectDirs]new().().unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("Could not get home directory"));
41 }