Crates.io | user_dirs |
lib.rs | user_dirs |
version | |
source | src |
created_at | 2024-12-03 04:08:59.173623 |
updated_at | 2024-12-08 23:57:57.233539 |
description | A respectful, XDG-first user directories implementation for obtaining the home, cache, config, data, runtime, and state directories |
homepage | https://github.com/uncenter/user_dirs |
repository | https://github.com/uncenter/user_dirs |
max_upload_size | |
id | 1469647 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
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 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.
For a user named Leah:
user_dirs::home_dir();
// See the [`home`](https://docs.rs/home) crate.
user_dirs::cache_dir();
// XDG? => $XDG_CACHE_HOME
// macOS => /Users/Leah/Library/Caches
// Windows => C:\Users\Leah\AppData\Local
// Linux => /home/leah/.cache
user_dirs::config_dir();
// XDG? => $XDG_CONFIG_HOME
// macOS => /Users/Leah/Library/Preferences
// Windows => C:\Users\Leah\AppData\Roaming
// Linux => /home/leah/.config
user_dirs::data_dir();
// XDG? => $XDG_DATA_HOME
// macOS => /Users/Leah/Library/Application Support
// Windows => C:\Users\Leah\AppData\Roaming
// Linux => /home/leah/.local/share
user_dirs::runtime_dir();
// XDG? => Some($XDG_RUNTIME_DIR)
// macOS => None
// Windows => None
// Linux => None
user_dirs::state_dir();
// XDG? => Some($XDG_STATE_HOME)
// macOS => None
// Windows => None
// Linux => Some(/home/leah/.local/state)
The crate also exposes an os
module, which provides functions for obtaining the operating system specified directory locations without XDG variable involvement. (This replicates the behavior of the dirs
crate.) Without XDG variables set, user_dirs::config_dir()
and user_dirs::os::config_dir()
should be equivalent.