|
1 | 1 | //! The _dirs_ crate is
|
2 | 2 | //!
|
3 |
| -//! - a tiny library with a minimal API (16 functions) |
| 3 | +//! - a tiny library with a minimal API (18 public functions) |
4 | 4 | //! - that provides the platform-specific, user-accessible locations
|
5 | 5 | //! - for finding and storing configuration, cache and other data
|
6 | 6 | //! - on Linux, Redox, Windows (≥ Vista) and macOS.
|
@@ -158,6 +158,22 @@ pub fn preference_dir() -> Option<PathBuf> {
|
158 | 158 | pub fn runtime_dir() -> Option<PathBuf> {
|
159 | 159 | sys::runtime_dir()
|
160 | 160 | }
|
| 161 | +/// Returns the path to the user's state directory. |
| 162 | +/// |
| 163 | +/// The state directory contains data that should be retained between sessions (unlike the runtime |
| 164 | +/// directory), but may not be important/portable enough to be synchronized across machines (unlike |
| 165 | +/// the config/preferences/data directories). |
| 166 | +/// |
| 167 | +/// The returned value depends on the operating system and is either a `Some`, containing a value from the following table, or a `None`. |
| 168 | +/// |
| 169 | +/// |Platform | Value | Example | |
| 170 | +/// | ------- | ----------------------------------------- | ------------------------ | |
| 171 | +/// | Linux | `$XDG_STATE_HOME` or `$HOME`/.local/state | /home/alice/.local/state | |
| 172 | +/// | macOS | – | – | |
| 173 | +/// | Windows | – | – | |
| 174 | +pub fn state_dir() -> Option<PathBuf> { |
| 175 | + sys::state_dir() |
| 176 | +} |
161 | 177 |
|
162 | 178 | /// Returns the path to the user's audio directory.
|
163 | 179 | ///
|
@@ -274,15 +290,18 @@ mod tests {
|
274 | 290 | #[test]
|
275 | 291 | fn test_dirs() {
|
276 | 292 | println!("home_dir: {:?}", ::home_dir());
|
| 293 | + println!(); |
277 | 294 | println!("cache_dir: {:?}", ::cache_dir());
|
278 | 295 | println!("config_dir: {:?}", ::config_dir());
|
279 | 296 | println!("data_dir: {:?}", ::data_dir());
|
280 | 297 | println!("data_local_dir: {:?}", ::data_local_dir());
|
281 | 298 | println!("executable_dir: {:?}", ::executable_dir());
|
282 | 299 | println!("preference_dir: {:?}", ::preference_dir());
|
283 | 300 | println!("runtime_dir: {:?}", ::runtime_dir());
|
| 301 | + println!("state_dir: {:?}", ::state_dir()); |
| 302 | + println!(); |
284 | 303 | println!("audio_dir: {:?}", ::audio_dir());
|
285 |
| - println!("home_dir: {:?}", ::desktop_dir()); |
| 304 | + println!("desktop_dir: {:?}", ::desktop_dir()); |
286 | 305 | println!("cache_dir: {:?}", ::document_dir());
|
287 | 306 | println!("config_dir: {:?}", ::download_dir());
|
288 | 307 | println!("font_dir: {:?}", ::font_dir());
|
|
0 commit comments