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.
- xdg_
bin_ home_ or - Returns the XDG binary directory, or a custom default.
- xdg_
cache_ home_ or - Returns the XDG cache directory, or a custom default.
- xdg_
config_ home_ or - Returns the XDG configuration directory, or a custom default.
- xdg_
data_ home_ or - Returns the XDG data directory, or a custom default.
- xdg_
desktop_ dir_ or - Returns the XDG desktop directory, or a custom default.
- xdg_
documents_ dir_ or - Returns the XDG documents directory, or a custom default.
- xdg_
download_ dir_ or - Returns the XDG download directory, or a custom default.
- xdg_
music_ dir_ or - Returns the XDG music directory, or a custom default.
- xdg_
pictures_ dir_ or - Returns the XDG pictures directory, or a custom default.
- xdg_
publicshare_ dir_ or - Returns the XDG public share directory, or a custom default.
- xdg_
runtime_ dir_ or - Returns the XDG runtime directory, or a custom default.
- xdg_
state_ home_ or - Returns the XDG state directory, or a custom default.
- xdg_
templates_ dir_ or - Returns the XDG templates directory, or a custom default.
- xdg_
videos_ dir_ or - Returns the XDG videos directory, or a custom default.