use std::path::PathBuf;
#[cfg(any(unix, test))]
mod unix;
#[cfg(windows)]
mod windows;
#[derive(Clone, Copy)]
enum Directory {
Home,
Cache,
Config,
LocalData,
}
pub fn home_dir() -> Option<PathBuf> {
directory(Directory::Home)
}
pub fn cache_dir() -> Option<PathBuf> {
directory(Directory::Cache)
}
pub fn config_dir() -> Option<PathBuf> {
directory(Directory::Config)
}
pub fn data_local_dir() -> Option<PathBuf> {
directory(Directory::LocalData)
}
fn directory(kind: Directory) -> Option<PathBuf> {
#[cfg(windows)]
{
windows::directory(kind)
}
#[cfg(unix)]
{
unix::directory(
kind,
cfg!(any(target_os = "macos", target_os = "ios")),
|key| std::env::var_os(key),
std::env::home_dir,
)
}
#[cfg(not(any(windows, unix)))]
{
let _ = kind;
None
}
}
#[cfg(test)]
mod tests;