use camino::{Utf8Path, Utf8PathBuf};
#[cfg(target_os = "macos")]
mod mac;
#[cfg(target_os = "macos")]
use mac::Info;
#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios"))))]
mod unix;
#[cfg(all(
unix,
not(any(target_os = "macos", target_os = "ios"))
))]
use unix::Info;
trait LocalInfo {
fn get_cache_home(&self) -> Utf8PathBuf;
fn get_config_home(&self) -> Utf8PathBuf;
fn get_data_home(&self) -> Utf8PathBuf;
fn get_log_home(&self) -> Utf8PathBuf;
fn get_state_home(&self) -> Utf8PathBuf;
}
pub struct LocalDirectories {
info: Box<dyn LocalInfo>,
}
impl LocalDirectories {
pub fn new<T>(
app_name: &str,
home: &T,
) -> Self
where
T: AsRef<Utf8Path> + ?Sized,
{
let info = Box::new(Info::new(app_name, home));
Self { info }
}
pub fn get_cache_home(&self) -> Utf8PathBuf {
self.info.get_cache_home()
}
pub fn get_config_home(&self) -> Utf8PathBuf {
self.info.get_config_home()
}
pub fn get_data_home(&self) -> Utf8PathBuf {
self.info.get_data_home()
}
pub fn get_log_home(&self) -> Utf8PathBuf {
self.info.get_log_home()
}
pub fn get_state_home(&self) -> Utf8PathBuf {
self.info.get_state_home()
}
}