user_dirs
A respectful, XDG-first user directories implementation for obtaining the home, cache, config, data, runtime, and state directories.
The library provides the location of these directories by leveraging the mechanisms defined by
- the XDG base directory on all platforms primarily,
- the Known Folder API on Windows,
- and the Standard Directories guidelines on macOS.
Why?
The key differentiator of the user_dirs crate is that it always prefers user-defined XDG variables, regardless of platform. Then and only then are system-defined directories used. The developer of the popular dirs and directories crates has refused time and time again to respect explicitly-defined XDG variables.
I'm a big fan of the etcetera library, however it overcomplicates the process by providing multiple strategies; user_dirs picks one.
Examples
For a user named Leah:
home_dir;
// See the [`home`](https://docs.rs/home) crate.
cache_dir;
// XDG? => $XDG_CACHE_HOME
// macOS => /Users/Leah/Library/Caches
// Windows => C:\Users\Leah\AppData\Local
// Linux => /home/leah/.cache
config_dir;
// XDG? => $XDG_CONFIG_HOME
// macOS => /Users/Leah/Library/Preferences
// Windows => C:\Users\Leah\AppData\Roaming
// Linux => /home/leah/.config
data_dir;
// XDG? => $XDG_DATA_HOME
// macOS => /Users/Leah/Library/Application Support
// Windows => C:\Users\Leah\AppData\Roaming
// Linux => /home/leah/.local/share
runtime_dir;
// XDG? => Some($XDG_RUNTIME_DIR)
// macOS => None
// Windows => None
// Linux => None
state_dir;
// XDG? => Some($XDG_STATE_HOME)
// macOS => None
// Windows => None
// Linux => Some(/home/leah/.local/state)