Expand description
§dir_spec
Cross-platform directory resolver with XDG compliance.
This crate provides functions to resolve standard directories across Linux, macOS, and Windows while respecting XDG Base Directory Specification environment variables when set.
§XDG Compliance
All functions check for corresponding XDG environment variables first (e.g., XDG_CONFIG_HOME
),
and only fall back to platform-specific defaults if the XDG variable is not set or contains
a relative path (which the XDG spec requires to be ignored).
§Examples
use dir_spec::{config_home, cache_home, videos};
// Get config directory (respects XDG_CONFIG_HOME if set)
if let Some(config) = config_home() {
println!("Config directory: {}", config.display());
}
// Get cache directory (respects XDG_CACHE_HOME if set)
if let Some(cache) = cache_home() {
println!("Cache directory: {}", cache.display());
}
// Get videos directory
if let Some(videos) = videos() {
println!("Videos directory: {}", videos.display());
}
Functions§
- bin_
home - Returns the user’s binary directory.
- cache_
home - Returns the user’s cache directory.
- config_
home - Returns the user’s configuration directory.
- config_
local - Returns the user’s local configuration directory (non-roaming).
- data_
home - Returns the user’s data directory.
- data_
local - Returns the user’s local data directory (non-roaming).
- desktop
- Returns the user’s desktop directory.
- documents
- Returns the user’s documents directory.
- downloads
- Returns the user’s downloads directory.
- fonts
- Returns the user’s fonts directory.
- home
- Returns the user’s home directory.
- music
- Returns the user’s music directory.
- pictures
- Returns the user’s pictures directory.
- preferences
- Returns the user’s preferences directory.
- publicshare
- Returns the user’s public share directory.
- runtime
- Returns the user’s runtime directory.
- state_
home - Returns the user’s state directory.
- templates
- Returns the user’s templates directory.
- videos
- Returns the user’s videos directory.