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

..03-May-2022-

src/H03-May-2022-397188

.appveyor.ymlH A D21-Jun-20201.6 KiB6861

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

.cargo_vcs_info.jsonH A D04-Jul-202074 65

.gitignoreH A D21-Jun-202036 54

.travis.ymlH A D21-Jun-2020234 2518

Cargo.tomlH A D04-Jul-20201.1 KiB2422

Cargo.toml.orig-cargoH A D04-Jul-2020718 1412

LICENSE-APACHEH A D21-Jun-20209.5 KiB175149

LICENSE-MITH A D21-Jun-20201 KiB2016

README.mdH A D04-Jul-202013.3 KiB211163

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/dirs-dev/dirs-rs/master.svg?label=Linux/macOS%20build)](https://travis-ci.org/dirs-dev/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 except for Redox, where the minimum Rust version
30depends on the [`redox_users`](https://crates.io/crates/redox_users) crate.
31
32It's mid-level sister library, _directories_, is available for Rust ([directories-rs](https://github.com/dirs-dev/directories-rs))
33and on the JVM ([directories-jvm](https://github.com/dirs-dev/directories-jvm)).
34
35## Usage
36
37#### Dependency
38
39Add the library as a dependency to your project by inserting
40
41```toml
42dirs = "3.0"
43```
44
45into the `[dependencies]` section of your Cargo.toml file.
46
47If you are upgrading from version 2, please read the [section on breaking changes](#3) first.
48
49#### Example
50
51Library run by user Alice:
52
53```rust
54extern crate dirs;
55
56dirs::home_dir();
57// Lin: Some(/home/alice)
58// Win: Some(C:\Users\Alice)
59// Mac: Some(/Users/Alice)
60
61dirs::audio_dir();
62// Lin: Some(/home/alice/Music)
63// Win: Some(C:\Users\Alice\Music)
64// Mac: Some(/Users/Alice/Music)
65
66dirs::config_dir();
67// Lin: Some(/home/alice/.config)
68// Win: Some(C:\Users\Alice\AppData\Roaming)
69// Mac: Some(/Users/Alice/Library/Application Support)
70
71dirs::executable_dir();
72// Lin: Some(/home/alice/.local/bin)
73// Win: None
74// Mac: None
75```
76
77## Design Goals
78
79- The _dirs_ library is a low-level crate designed to provide the paths to standard directories
80  as defined by operating systems rules or conventions.<br/>
81  If your requirements are more complex, e. g. computing cache, config, etc. paths for specific
82  applications or projects, consider using [directories](https://github.com/dirs-dev/directories-rs)
83  instead.
84- This library does not create directories or check for their existence. The library only provides
85  information on what the path to a certain directory _should_ be.<br/>
86  How this information is used is a decision that developers need to make based on the requirements
87  of each individual application.
88- This library is intentionally focused on providing information on user-writable directories only,
89  as there is no discernible benefit in returning a path that points to a user-level, writable
90  directory on one operating system, but a system-level, read-only directory on another.<br/>
91  The confusion and unexpected failure modes of such an approach would be immense.
92  - `executable_dir` is specified to provide the path to a user-writable directory for binaries.<br/>
93    As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows.
94  - `font_dir` is specified to provide the path to a user-writable directory for fonts.<br/>
95    As such a directory only exists on Linux and macOS, it returns `None` on Windows.
96  - `runtime_dir` is specified to provide the path to a directory for non-essential runtime data.
97    It is required that this directory is created when the user logs in, is only accessible by the
98    user itself, is deleted when the user logs out, and supports all filesystem features of the
99    operating system.<br/>
100    As such a directory only commonly exists on Linux, it returns `None` on macOS and Windows.
101
102## Features
103
104**If you want to compute the location of cache, config or data directories for your own application or project,
105use `ProjectDirs` of the [directories](https://github.com/dirs-dev/directories-rs) project instead.**
106
107| Function name    | Value on Linux/Redox                                                                             | Value on Windows                  | Value on macOS                              |
108| ---------------- | ------------------------------------------------------------------------------------------------ | --------------------------------- | ------------------------------------------- |
109| `home_dir`       | `Some($HOME)`                                                                                    | `Some({FOLDERID_Profile})`        | `Some($HOME)`                               |
110| `cache_dir`      | `Some($XDG_CACHE_HOME)`         or `Some($HOME`/.cache`)`                                        | `Some({FOLDERID_LocalAppData})`   | `Some($HOME`/Library/Caches`)`              |
111| `config_dir`     | `Some($XDG_CONFIG_HOME)`        or `Some($HOME`/.config`)`                                       | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
112| `data_dir`       | `Some($XDG_DATA_HOME)`          or `Some($HOME`/.local/share`)`                                  | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Application Support`)` |
113| `data_local_dir` | `Some($XDG_DATA_HOME)`          or `Some($HOME`/.local/share`)`                                  | `Some({FOLDERID_LocalAppData})`   | `Some($HOME`/Library/Application Support`)` |
114| `executable_dir` | `Some($XDG_BIN_HOME`/../bin`)`  or `Some($XDG_DATA_HOME`/../bin`)` or `Some($HOME`/.local/bin`)` | `None`                            | `None`                                      |
115| `preference_dir` | `Some($XDG_CONFIG_HOME)`        or `Some($HOME`/.config`)`                                       | `Some({FOLDERID_RoamingAppData})` | `Some($HOME`/Library/Preferences`)`         |
116| `runtime_dir`    | `Some($XDG_RUNTIME_DIR)`        or `None`                                                        | `None`                            | `None`                                      |
117| `audio_dir`      | `Some(XDG_MUSIC_DIR)`           or `None`                                                        | `Some({FOLDERID_Music})`          | `Some($HOME`/Music/`)`                      |
118| `desktop_dir`    | `Some(XDG_DESKTOP_DIR)`         or `None`                                                        | `Some({FOLDERID_Desktop})`        | `Some($HOME`/Desktop/`)`                    |
119| `document_dir`   | `Some(XDG_DOCUMENTS_DIR)`       or `None`                                                        | `Some({FOLDERID_Documents})`      | `Some($HOME`/Documents/`)`                  |
120| `download_dir`   | `Some(XDG_DOWNLOAD_DIR)`        or `None`                                                        | `Some({FOLDERID_Downloads})`      | `Some($HOME`/Downloads/`)`                  |
121| `font_dir`       | `Some($XDG_DATA_HOME`/fonts/`)` or `Some($HOME`/.local/share/fonts/`)`                           | `None`                            | `Some($HOME`/Library/Fonts/`)`              |
122| `picture_dir`    | `Some(XDG_PICTURES_DIR)`        or `None`                                                        | `Some({FOLDERID_Pictures})`       | `Some($HOME`/Pictures/`)`                   |
123| `public_dir`     | `Some(XDG_PUBLICSHARE_DIR)`     or `None`                                                        | `Some({FOLDERID_Public})`         | `Some($HOME`/Public/`)`                     |
124| `template_dir`   | `Some(XDG_TEMPLATES_DIR)`       or `None`                                                        | `Some({FOLDERID_Templates})`      | `None`                                      |
125| `video_dir`      | `Some(XDG_VIDEOS_DIR)`          or `None`                                                        | `Some({FOLDERID_Videos})`         | `Some($HOME`/Movies/`)`                     |
126
127## Comparison
128
129There are other crates in the Rust ecosystem that try similar or related things.
130Here is an overview of them, combined with ratings on properties that guided the design of this crate.
131
132Please take this table with a grain of salt: a different crate might very well be more suitable for your specific use case.
133(Of course _my_ crate achieves _my_ design goals better than other crates, which might have had different design goals.)
134
135| Library                                                   | Status         | Lin | Mac | Win |Base|User|Proj|Conv|
136| --------------------------------------------------------- | -------------- |:---:|:---:|:---:|:--:|:--:|:--:|:--:|
137| [app_dirs](https://crates.io/crates/app_dirs)             | Unmaintained   |  ✔  |  ✔  |  ✔  | ��  | ✖  | ✔  | ✖  |
138| [app_dirs2](https://crates.io/crates/app_dirs2)           | Maintained     |  ✔  |  ✔  |  ✔  | ��  | ✖  | ✔  | ✖  |
139| **dirs**                                                  | **Developed**  |  ✔  |  ✔  |  ✔  | ✔  | ✔  | ✖  | ✔  |
140| [directories](https://crates.io/crates/directories)       | Developed      |  ✔  |  ✔  |  ✔  | ✔  | ✔  | ✔  | ✔  |
141| [s_app_dir](https://crates.io/crates/s_app_dir)           | Unmaintained?  |  ✔  |  ✖  |  ��  | ✖  | ✖  | ��  | ✖  |
142| [standard_paths](https://crates.io/crates/standard_paths) | Maintained     |  ✔  |  ✖  |  ✔  | ✔  | ✔  | ✔  | ✖  |
143| [xdg](https://crates.io/crates/xdg)                       | Maintained     |  ✔  |  ✖  |  ✖  | ✔  | ✖  | ✔  | ��  |
144| [xdg-basedir](https://crates.io/crates/xdg-basedir)       | Unmaintained?  |  ✔  |  ✖  |  ✖  | ✔   | ✖  | ✖  | ��  |
145| [xdg-rs](https://crates.io/crates/xdg-rs)                 | Obsolete       |  ✔  |  ✖  |  ✖  | ✔   | ✖  | ✖  | ��  |
146
147- Lin: Linux support
148- Mac: macOS support
149- Win: Windows support
150- Base: Supports [generic base directories](https://github.com/dirs-dev/directories-rs#basedirs)
151- User: Supports [user directories](https://github.com/dirs-dev/directories-rs#userdirs)
152- Proj: Supports [project-specific base directories](https://github.com/dirs-dev/directories-rs#projectdirs)
153- Conv: Follows naming conventions of the operating system it runs on
154
155## Build
156
157It's possible to cross-compile this library if the necessary toolchains are installed with rustup.
158This is helpful to ensure a change hasn't broken code on a different platform.
159
160The following commands will build this library on Linux, macOS and Windows:
161
162```
163cargo build --target=x86_64-unknown-linux-gnu
164cargo build --target=x86_64-pc-windows-gnu
165cargo build --target=x86_64-apple-darwin
166cargo build --target=x86_64-unknown-redox
167```
168
169## Changelog
170
171### 3
172
173- **BREAKING CHANGE** The behavior of `config_dir` on macOS has been adjusted
174  (thanks to [everyone involved](https://github.com/dirs-dev/directories-rs/issues/62)):
175  - The existing `config_dir` function has been changed to return the `Application Support`
176    directory on macOS, as suggested by Apple documentation.
177  - The behavior of the `config_dir` function on non-macOS platforms has not been changed.
178  - If you have used the `config_dir` function to store files, it may be necessary to write code
179    that migrates the files to the new location on macOS.<br/>
180    (Alternative: change uses of the `config_dir` function to uses of the `preference_dir` function
181    to retain the old behavior.)
182- The newly added `preference_dir` function returns the `Preferences` directory on macOS now,
183  which – according to Apple documentation – shall only be used to store .plist files using
184  Apple-proprietary APIs.
185  – `preference_dir` and `config_dir` behave identical on non-macOS platforms.
186
187### 2
188
189The behavior of deactivated, missing or invalid [_XDG User Dirs_](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)
190entries on Linux has been improved (contributed by @tmiasko, thank you!):
191
192- Version 1 returned the user's home directory (`Some($HOME)`) for such faulty entries, except for a faulty `XDG_DESKTOP_DIR` entry which returned (`Some($HOME/Desktop)`).
193- Version 2 returns `None` for such entries.
194
195## License
196
197Licensed under either of
198
199 * Apache License, Version 2.0
200   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
201 * MIT license
202   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
203
204at your option.
205
206## Contribution
207
208Unless you explicitly state otherwise, any contribution intentionally submitted
209for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
210dual licensed as above, without any additional terms or conditions.
211