pub struct AppDirs {
pub cache_dir: PathBuf,
pub config_dir: PathBuf,
pub data_dir: PathBuf,
pub state_dir: PathBuf,
}
Fields§
§cache_dir: PathBuf
§config_dir: PathBuf
§data_dir: PathBuf
§state_dir: PathBuf
Implementations§
Source§impl AppDirs
impl AppDirs
Sourcepub fn new(name: Option<&str>, use_xdg_on_macos: bool) -> Option<Self>
pub fn new(name: Option<&str>, use_xdg_on_macos: bool) -> Option<Self>
Examples found in repository?
examples/config_file.rs (line 6)
5 6 7 8 9 10 11 12 13 14 15 16
fn main() {
let app_dirs = AppDirs::new(Some("name"), true).unwrap();
let config_file_path = app_dirs.config_dir.join("config-file");
fs::create_dir_all(&app_dirs.config_dir).unwrap();
let file = if config_file_path.exists() {
File::open(config_file_path).unwrap()
} else {
File::create(config_file_path).unwrap()
};
}
More examples
examples/basic.rs (line 4)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
fn main() {
let app_dirs = AppDirs::new(Some("name"), false).unwrap();
dbg!(&app_dirs);
// AppDirs {
// cache_dir: "/home/cjbassi/.cache/name",
// config_dir: "/home/cjbassi/.config/name",
// data_dir: "/home/cjbassi/.local/share/name",
// state_dir: "/home/cjbassi/.local/state/name"
// }
let user_dirs = UserDirs::new().unwrap();
dbg!(&user_dirs);
// UserDirs {
// desktop_dir: "/home/cjbassi/Desktop",
// document_dir: "/home/cjbassi/Documents",
// download_dir: "/home/cjbassi/Downloads",
// music_dir: "/home/cjbassi/Music",
// picture_dir: "/home/cjbassi/Pictures",
// public_dir: "/home/cjbassi/Public",
// video_dir: "/home/cjbassi/Videos"
// }
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AppDirs
impl RefUnwindSafe for AppDirs
impl Send for AppDirs
impl Sync for AppDirs
impl Unpin for AppDirs
impl UnwindSafe for AppDirs
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)