use crate::HomeDirError;
use std::path::{Path, PathBuf};
pub trait BaseStrategy {
fn home_dir(&self) -> &Path;
fn config_dir(&self) -> PathBuf;
fn data_dir(&self) -> PathBuf;
fn cache_dir(&self) -> PathBuf;
fn state_dir(&self) -> Option<PathBuf>;
fn runtime_dir(&self) -> Option<PathBuf>;
}
macro_rules! create_strategies {
($native: ty, $base: ty) => {
pub fn choose_native_strategy() -> Result<$native, HomeDirError> {
<$native>::new()
}
pub fn choose_base_strategy() -> Result<$base, HomeDirError> {
<$base>::new()
}
};
}
cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
create_strategies!(Windows, Windows);
} else if #[cfg(any(target_os = "macos", target_os = "ios"))] {
create_strategies!(Apple, Xdg);
} else {
create_strategies!(Xdg, Xdg);
}
}
mod apple;
mod windows;
mod xdg;
pub use apple::Apple;
pub use windows::Windows;
pub use xdg::Xdg;