use std::path::Path;
use std::path::PathBuf;
#[cfg(target_os = "linux")] mod lin;
#[cfg(target_os = "windows")] mod win;
#[cfg(target_os = "macos")] mod mac;
#[derive(Debug, Clone)]
pub struct BaseDirs {
home_dir: PathBuf,
cache_dir: PathBuf,
config_dir: PathBuf,
data_dir: PathBuf,
data_local_dir: PathBuf,
executable_dir: Option<PathBuf>,
runtime_dir: Option<PathBuf>,
}
#[derive(Debug, Clone)]
pub struct UserDirs {
home_dir: PathBuf,
audio_dir: Option<PathBuf>,
desktop_dir: Option<PathBuf>,
document_dir: Option<PathBuf>,
download_dir: Option<PathBuf>,
font_dir: Option<PathBuf>,
picture_dir: Option<PathBuf>,
public_dir: Option<PathBuf>,
template_dir: Option<PathBuf>,
video_dir: Option<PathBuf>
}
#[derive(Debug, Clone)]
pub struct ProjectDirs {
project_path: PathBuf,
cache_dir: PathBuf,
config_dir: PathBuf,
data_dir: PathBuf,
data_local_dir: PathBuf,
runtime_dir: Option<PathBuf>
}
#[deny(missing_docs)]
impl BaseDirs {
pub fn home_dir(&self) -> &Path {
self.home_dir.as_path()
}
pub fn cache_dir(&self) -> &Path {
self.cache_dir.as_path()
}
pub fn config_dir(&self) -> &Path {
self.config_dir.as_path()
}
pub fn data_dir(&self) -> &Path {
self.data_dir.as_path()
}
pub fn data_local_dir(&self) -> &Path {
self.data_local_dir.as_path()
}
pub fn executable_dir(&self) -> Option<&Path> {
self.executable_dir.as_ref().map(|p| p.as_path())
}
pub fn runtime_dir(&self) -> Option<&Path> {
self.runtime_dir.as_ref().map(|p| p.as_path())
}
}
#[deny(missing_docs)]
impl UserDirs {
pub fn home_dir(&self) -> &Path {
self.home_dir.as_path()
}
pub fn audio_dir(&self) -> Option<&Path> {
self.audio_dir.as_ref().map(|p| p.as_path())
}
pub fn desktop_dir(&self) -> Option<&Path> {
self.desktop_dir.as_ref().map(|p| p.as_path())
}
pub fn document_dir(&self) -> Option<&Path> {
self.document_dir.as_ref().map(|p| p.as_path())
}
pub fn download_dir(&self) -> Option<&Path> {
self.download_dir.as_ref().map(|p| p.as_path())
}
pub fn font_dir(&self) -> Option<&Path> {
self.font_dir.as_ref().map(|p| p.as_path())
}
pub fn picture_dir(&self) -> Option<&Path> {
self.picture_dir.as_ref().map(|p| p.as_path())
}
pub fn public_dir(&self) -> Option<&Path> {
self.public_dir.as_ref().map(|p| p.as_path())
}
pub fn template_dir(&self) -> Option<&Path> {
self.template_dir.as_ref().map(|p| p.as_path())
}
pub fn video_dir(&self) -> Option<&Path> {
self.video_dir.as_ref().map(|p| p.as_path())
}
}
#[deny(missing_docs)]
impl ProjectDirs {
pub fn project_path(&self) -> &Path {
self.project_path.as_path()
}
pub fn cache_dir(&self) -> &Path {
self.cache_dir.as_path()
}
pub fn config_dir(&self) -> &Path {
self.config_dir.as_path()
}
pub fn data_dir(&self) -> &Path {
self.data_dir.as_path()
}
pub fn data_local_dir(&self) -> &Path {
self.data_local_dir.as_path()
}
pub fn runtime_dir(&self) -> Option<&Path> {
self.runtime_dir.as_ref().map(|p| p.as_path())
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_base_dirs() {
println!("BaseDirs::new())\n{:?}", ::BaseDirs::new());
}
#[test]
fn test_user_dirs() {
println!("UserDirs::new())\n{:?}", ::UserDirs::new());
}
#[test]
fn test_project_dirs() {
let proj_dirs = ::ProjectDirs::from("qux", "FooCorp", "BarApp");
println!("ProjectDirs::from(\"qux\", \"FooCorp\", \"BarApp\")\n{:?}", proj_dirs);
let proj_dirs = ::ProjectDirs::from("qux.zoo", "Foo Corp", "Bar-App");
println!("ProjectDirs::from(\"qux.zoo\", \"Foo Corp\", \"Bar-App\")\n{:?}", proj_dirs);
let proj_dirs = ::ProjectDirs::from("com", "Foo Corp.", "Bar App");
println!("ProjectDirs::from(\"com\", \"Foo Corp.\", \"Bar App\")\n{:?}", proj_dirs);
}
}