Skip to main content

Crate dir_spec

Crate dir_spec 

Source
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.