Skip to main content

hotl_platform/paths/
unix.rs

1//! XDG, with the `$HOME`-relative defaults the spec prescribes.
2
3use super::{env_path, KnownPaths};
4use std::path::PathBuf;
5
6#[derive(Debug, Clone, Copy, Default)]
7pub struct UnixKnownPaths;
8
9impl UnixKnownPaths {
10    pub const fn new() -> Self {
11        Self
12    }
13}
14
15impl crate::sealed::Sealed for UnixKnownPaths {}
16
17impl KnownPaths for UnixKnownPaths {
18    fn home(&self) -> Option<PathBuf> {
19        env_path("HOME")
20    }
21
22    fn config(&self) -> Option<PathBuf> {
23        env_path("XDG_CONFIG_HOME")
24            .or_else(|| self.home().map(|h| h.join(".config")))
25            .map(|b| b.join("hotl"))
26    }
27
28    fn data(&self) -> Option<PathBuf> {
29        env_path("XDG_DATA_HOME")
30            .or_else(|| self.home().map(|h| h.join(".local/share")))
31            .map(|b| b.join("hotl"))
32    }
33
34    fn runtime(&self) -> Option<PathBuf> {
35        env_path("XDG_RUNTIME_DIR").map(|b| b.join("hotl"))
36    }
37}