• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

src/H03-May-2022-488274

.appveyor.ymlH A D27-Feb-20191.6 KiB6861

.cargo-checksum.jsonH A D03-May-202289 11

.cargo_vcs_info.jsonH A D01-Jan-197074 65

.gitignoreH A D05-Jul-201830 43

.travis.ymlH A D27-Feb-2019289 3022

Cargo.tomlH A D01-Jan-19701.4 KiB2927

Cargo.toml.orig-cargoH A D27-Feb-2019943 2016

LICENSE-APACHEH A D05-Jul-20189.5 KiB175149

LICENSE-MITH A D27-Feb-20191 KiB2016

README.mdH A D27-Feb-201911.4 KiB178137

README.md

1[![crates.io](https://img.shields.io/crates/v/dirs.svg)](https://crates.io/crates/dirs)
2[![API documentation](https://docs.rs/dirs/badge.svg)](https://docs.rs/dirs/)
3![actively developed](https://img.shields.io/badge/maintenance-actively--developed-brightgreen.svg)
4[![TravisCI status](https://img.shields.io/travis/soc/dirs-rs/master.svg?label=Linux/macOS%20build)](https://travis-ci.org/soc/dirs-rs)
5[![AppVeyor status](https://img.shields.io/appveyor/ci/soc/dirs-rs/master.svg?label=Windows%20build)](https://ci.appveyor.com/project/soc/dirs-rs/branch/master)
6![License: MIT/Apache-2.0](https://img.shields.io/badge/license-MIT%2FApache--2.0-orange.svg)
7
8# `dirs`
9
10## Introduction
11
12- a tiny low-level library with a minimal API
13- that provides the platform-specific, user-accessible locations
14- for retrieving and storing configuration, cache and other data
15- on Linux, Redox, Windows (≥ Vista), macOS and other platforms.
16
17The library provides the location of these directories by leveraging the mechanisms defined by
18- the [XDG base directory](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) and
19  the [XDG user directory](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/) specifications on Linux and Redox
20- the [Known Folder](https://msdn.microsoft.com/en-us/library/windows/desktop/dd378457.aspx) API on Windows
21- the [Standard Directories](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW6)
22  guidelines on macOS
23
24## Platforms
25
26This library is written in Rust, and supports Linux, Redox, macOS and Windows.
27Other platforms are also supported; they use the Linux conventions.
28
29The minimal required version of Rust is 1.13 on Linux and Windows, and 1.20 on macOS.
30
31It's mid-level sister library, _directories_, is available for Rust ([directories-rs](https://github.com/soc/directories-rs))
32and on the JVM ([directories-jvm](https://github.com/soc/directories-jvm)).
33
34## Usage
35
36#### Dependency
37
38Add the library as a dependency to your project by inserting
39
40```toml
41dirs = "1.0"
42```
43
44into the `[dependencies]` section of your Cargo.toml file.
45
46#### Example
47
48Library run by user Alice:
49
50```rust
51extern crate dirs;
52
53dirs::home_dir();
54// Lin: Some(/home/alice)
55// Win: Some(C:\Users\Alice)
56// Mac: Some(/Users/Alice)
57
58dirs::audio_dir();
59// Lin: Some(/home/alice/Music)
60// Win: Some(C:\Users\Alice\Music)
61// Mac: Some(/Users/Alice/Music)
62
63dirs::config_dir();
64// Lin: Some(/home/alice/.config)
65// Win: Some(C:\Users\Alice\AppData\Roaming)
66// Mac: Some(/Users/Alice/Library/Preferences)
67
68dirs::executable_dir();
69// Lin: Some(/home/alice/.local/bin)
70// Win: None
71// Mac: None
72```
73
74## Design Goals
75
76- The _dirs_ library is a low-level crate designed to provide the paths to standard directories
77  as defined by operating systems rules or conventions. If your requirements are more complex,
78  e. g. computing cache, config, etc. paths for specific applications or projects, consider using
79  [directories](https://github.com/soc/directories-rs) instead.
80- This library does not create directories or check for their existence. The library only provides
81  information on what the path to a certain directory _should_ be. How this information is used is
82  a decision that developers need to make based on the requirements of each individual application.
83- This library is intentionally focused on providing information on user-writable directories only.
84  There is no discernible benefit in returning a path that points to a user-level, writable
85  directory on one operating system, but a system-level, read-only directory on another, that would
86  outweigh the confusion and unexpected failures such an approach would cause.
87  - `executable_dir` is specified to provide the path to a user-writable directory for binaries.<br/>
88    As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows.
89  - `font_dir` is specified to provide the path to a user-writable directory for fonts.<br/>
90    As such a directory only exists on Linux and macOS, it returns `None` on Windows.
91  - `runtime_dir` is specified to provide the path to a directory for non-essential runtime data.
92    It is required that this directory is created when the user logs in, is only accessible by the
93    user itself, is deleted when the user logs out, and supports all filesystem features of the
94    operating system.<br/>
95    As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows.
96
97## Features
98
99**If you want to compute the location of cache, config or data directories for your own application or project,
100use `ProjectDirs` of the [directories](https://github.com/soc/directories-rs) project instead.**
101
102| Function name    | Value on Linux/Redox                                                                             | Value on Windows                  | Value on macOS                              |
103| ---------------- | ------------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------------- |
104| `home_dir`       | `Some($HOME)`                                                                                    | `Some({FOLDERID_Profile})`        | `Some($HOME)`                               |
105| `cache_dir`      | `Some($XDG_CACHE_HOME)`         or `Some($HOME`/.cache`)`                                        | `Some({FOLDERID_LocalAppData})`   | `Some($HOME`/Library/Caches`)`              |
106| `config_dir`     | `Some($XDG_CONFIG_HOME)`        or `Some($HOME`/.config`)`                                       | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Preferences`)`         |
107| `data_dir`       | `Some($XDG_DATA_HOME)`          or `Some($HOME`/.local/share`)`                                  | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
108| `data_local_dir` | `Some($XDG_DATA_HOME)`          or `Some($HOME`/.local/share`)`                                  | `Some({FOLDERID_LocalAppData})`   | `Some($HOME`/Library/Application Support`)` |
109| `executable_dir` | `Some($XDG_BIN_HOME`/../bin`)`  or `Some($XDG_DATA_HOME`/../bin`)` or `Some($HOME`/.local/bin`)` | `None`                            | `None`                                      |
110| `runtime_dir`    | `Some($XDG_RUNTIME_DIR)`        or `None`                                                        | `None`                            | `None`                                      |
111| `audio_dir`      | `Some(XDG_MUSIC_DIR)`           or `None`                                                        | `Some({FOLDERID_Music})`          | `Some($HOME`/Music/`)`                      |
112| `desktop_dir`    | `Some(XDG_DESKTOP_DIR)`         or `None`                                                        | `Some({FOLDERID_Desktop})`        | `Some($HOME`/Desktop/`)`                    |
113| `document_dir`   | `Some(XDG_DOCUMENTS_DIR)`       or `None`                                                        | `Some({FOLDERID_Documents})`      | `Some($HOME`/Documents/`)`                  |
114| `download_dir`   | `Some(XDG_DOWNLOAD_DIR)`        or `None`                                                        | `Some({FOLDERID_Downloads})`      | `Some($HOME`/Downloads/`)`                  |
115| `font_dir`       | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)`                           | `None`                            | `Some($HOME`/Library/Fonts/`)`              |
116| `picture_dir`    | `Some(XDG_PICTURES_DIR)`        or `None`                                                        | `Some({FOLDERID_Pictures})`       | `Some($HOME`/Pictures/`)`                   |
117| `public_dir`     | `Some(XDG_PUBLICSHARE_DIR)`     or `None`                                                        | `Some({FOLDERID_Public})`         | `Some($HOME`/Public/`)`                     |
118| `template_dir`   | `Some(XDG_TEMPLATES_DIR)`       or `None`                                                        | `Some({FOLDERID_Templates})`      | `None`                                      |
119| `video_dir`      | `Some(XDG_VIDEOS_DIR)`          or `None`                                                        | `Some({FOLDERID_Videos})`         | `Some($HOME`/Movies/`)`                     |
120
121## Comparison
122
123There are other crates in the Rust ecosystem that try similar or related things.
124Here is an overview of them, combined with ratings on properties that guided the design of this crate.
125
126Please take this table with a grain of salt: a different crate might very well be more suitable for your specific use case.
127(Of course _my_ crate achieves _my_ design goals better than other crates, which might have had different design goals.)
128
129| Library                                                   | Status         | Lin | Mac | Win |Base|User|Proj|Conv|
130| --------------------------------------------------------- | -------------- |:---:|:---:|:---:|:--:|:--:|:--:|:--:|
131| [app_dirs](https://crates.io/crates/app_dirs)             | Unmaintained   |  ✔  |  ✔  |  ✔  | ��  | ✖  | ✔  | ✖  |
132| [app_dirs2](https://crates.io/crates/app_dirs2)           | Maintained     |  ✔  |  ✔  |  ✔  | ��  | ✖  | ✔  | ✖  |
133| **dirs**                                                  | **Developed**  |  ✔  |  ✔  |  ✔  | ✔  | ✔  | ✖  | ✔  |
134| [directories](https://crates.io/crates/directories)       | Developed      |  ✔  |  ✔  |  ✔  | ✔  | ✔  | ✔  | ✔  |
135| [s_app_dir](https://crates.io/crates/s_app_dir)           | Unmaintained?  |  ✔  |  ✖  |  ��  | ✖  | ✖  | ��  | ✖  |
136| [standard_paths](https://crates.io/crates/standard_paths) | Maintained     |  ✔  |  ✖  |  ✔  | ✔  | ✔  | ✔  | ✖  |
137| [xdg](https://crates.io/crates/xdg)                       | Maintained     |  ✔  |  ✖  |  ✖  | ✔  | ✖  | ✔  | ��  |
138| [xdg-basedir](https://crates.io/crates/xdg-basedir)       | Unmaintained?  |  ✔  |  ✖  |  ✖  | ✔   | ✖  | ✖  | ��  |
139| [xdg-rs](https://crates.io/crates/xdg-rs)                 | Obsolete       |  ✔  |  ✖  |  ✖  | ✔   | ✖  | ✖  | ��  |
140
141- Lin: Linux support
142- Mac: macOS support
143- Win: Windows support
144- Base: Supports [generic base directories](https://github.com/soc/directories-rs#basedirs)
145- User: Supports [user directories](https://github.com/soc/directories-rs#userdirs)
146- Proj: Supports [project-specific base directories](https://github.com/soc/directories-rs#projectdirs)
147- Conv: Follows naming conventions of the operating system it runs on
148
149## Build
150
151It's possible to cross-compile this library if the necessary toolchains are installed with rustup.
152This is helpful to ensure a change hasn't broken code on a different platform.
153
154The following commands will build this library on Linux, macOS and Windows:
155
156```
157cargo build --target=x86_64-unknown-linux-gnu
158cargo build --target=x86_64-apple-darwin
159cargo build --target=x86_64-pc-windows-gnu
160```
161
162## License
163
164Licensed under either of
165
166 * Apache License, Version 2.0
167   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
168 * MIT license
169   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
170
171at your option.
172
173## Contribution
174
175Unless you explicitly state otherwise, any contribution intentionally submitted
176for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
177dual licensed as above, without any additional terms or conditions.
178