Directories
Introduction
- A tiny library with a minimal API (2 structs, 4 factory functions, getters)
- that provides the platform-specific, user-accessible locations
- for storing configuration, cache and other data
- on Linux, Windows (≥ Vista) and macOS.
The library provides the location of these directories by leveraging the mechanisms defined by
- the XDG base directory and the XDG user directory specifications on Linux,
- the Known Folder system on Windows, and
- the Standard Directories on macOS.
Usage
Dependency
Add the library as a dependency to your project by inserting
= "0.3.1"
into the [dependencies]
section of your Cargo.toml file.
Example
Library run by a user with user name "my_user_name" on Linux:
extern crate directories;
use ProjectDirectories;
let my_proj_dirs = ProjectDirectories.from_project_name;
my_proj_dirs.project_config_dir; // "/home/my_user_name/.config/my-project/"
Features
BaseDirectories
The intended use-case for BaseDirectories
is to query the paths of standard directories
that have been defined according to the conventions of operating system the library is running on.
If you want to compute the location of cache, config or data directories for your own application or project, use ProjectDirectories
instead.
Function name | Value on Linux | Value on Windows | Value on macOS |
---|---|---|---|
home_dir |
$HOME |
{FOLDERID_Profile} |
$HOME |
cache_dir |
$XDG_CACHE_DIR or ~/.cache/ |
{FOLDERID_LocalAppData}/cache/ |
$HOME/Library/Caches/ |
config_dir |
$XDG_CONFIG_DIR or ~/.config/ |
{FOLDERID_RoamingAppData} |
$HOME/Library/Preferences/ |
data_dir |
$XDG_DATA_DIR or ~/.local/share/ |
{FOLDERID_LocalAppData} |
$HOME/Library/Application Support/ |
data_roaming_dir |
$XDG_DATA_DIR or ~/.local/share/ |
{FOLDERID_RoamingAppData} |
$HOME/Library/Application Support/ |
executable_dir |
Some($XDG_DATA_HOME/../bin/) or Some($HOME/.local/bin/) |
None |
Some($HOME/Applications/) |
runtime_dir |
Some($XDG_RUNTIME_DIR) |
None |
None |
audio_dir |
XDG_MUSIC_DIR |
{FOLDERID_Music} |
$HOME/Music/ |
desktop_dir |
XDG_DESKTOP_DIR |
{FOLDERID_Desktop} |
$HOME/Desktop/ |
document_dir |
XDG_DOCUMENTS_DIR |
{FOLDERID_Documents} |
$HOME/Documents/ |
download_dir |
XDG_DOWNLOAD_DIR |
{FOLDERID_Downloads} |
$HOME/Downloads/ |
font_dir |
Some($XDG_DATA_HOME/fonts/) or Some($HOME/.local/share/fonts/) |
None |
Some($HOME/Library/Fonts/) |
picture_dir |
XDG_PICTURES_DIR |
{FOLDERID_Pictures} |
$HOME/Pictures/ |
public_dir |
XDG_PUBLICSHARE_DIR |
{FOLDERID_Public} |
$HOME/Public/ |
template_dir |
XDG_TEMPLATES_DIR |
{FOLDERID_Templates} |
None |
video_dir |
XDG_VIDEOS_DIR |
{FOLDERID_Videos} |
$HOME/Movies/ |
ProjectDirectories
The intended use-case for ProjectDirectories
is to compute the location of cache, config or data directories for your own application or project,
which are derived from the standard directories.
Function name | Value on Linux | Value on Windows | Value on macOS |
---|---|---|---|
project_cache_dir |
$XDG_CACHE_DIR/_yourprojectname_ or $HOME/.cache/_yourprojectname_/ |
{FOLDERID_LocalAppData}/_yourprojectname_/cache/ |
$HOME/Library/Caches/_yourprojectname_/ |
project_config_dir |
$XDG_CONFIG_DIR/_yourprojectname_ or $HOME/.config/_yourprojectname_/ |
{FOLDERID_RoamingAppData}/_yourprojectname_/ |
$HOME/Library/Preferences/_yourprojectname_/ |
project_data_dir |
$XDG_DATA_DIR/_yourprojectname_ or $HOME/.local/share/_yourprojectname_/ |
{FOLDERID_LocalAppData}/_yourprojectname_/ |
$HOME/Library/Application Support/_yourprojectname_/ |
project_data_roaming_dir |
$XDG_DATA_DIR/_yourprojectname_ or $HOME/.local/share/_yourprojectname_/ |
{FOLDERID_RoamingAppData}/_yourprojectname_/ |
$HOME/Library/Application Support/_yourprojectname_/ |
project_runtime_dir |
Some($XDG_RUNTIME_DIR/_yourprojectname_) or Some($HOME/.local/share/_yourprojectname_/) |
None |
None |
The specific value of _yourprojectname_
depends on the function used to create the ProjectDirectories
struct:
Function name | Example project name | Value on Linux | Value on Windows | Value on macOS |
---|---|---|---|---|
from_unprocessed_string |
"FooBar-App" |
"FooBar-App" |
"FooBar-App" |
"FooBar-App" |
from_project_name |
"FooBar App" |
"foobar-app" |
"FooBar App" |
"FooBar App" |
from_qualified_project_name |
"org.foobar-corp.FooBar-App" |
"foobar-app" |
"FooBar-App" |
"org.foobar-corp.FooBar-App" |
Versioning
After 1.0, the version number of this library consists of a whole number, which is incremented with each release. (Think semantic versioning without minor and patch versions.)