platform-dirs
A Rust library for resolving platform-dependent application and user directory paths.
Repository Health
Technical Analysis
platform-dirs is a small Rust library for obtaining the correct, platform-dependent directory paths for both application data and standard user folders. It abstracts away the differences between operating systems so your app writes config, cache, and data files where each platform expects them.
It follows the established conventions on every major platform: the XDG Base Directory and User Directory specs on Linux and *BSD, Apple’s Standard Directories on macOS, and the Known Folder API on Windows. Two simple types — AppDirs and UserDirs — expose the resolved paths.
What You Get
AppDirs— resolves cache, config, data, and state directories for your named application.UserDirs— resolves standard user folders (Desktop, Documents, Downloads, Music, and more).- Cross-platform support for Linux/*BSD (XDG), macOS (Standard Directories), and Windows (Known Folder).
- An option to place app directories in an XDG-style layout or platform-native layout.
- A tiny, dependency-light API returning ready-to-use
PathBufvalues.
Common Use Cases
- Deciding where to store an application’s config and cache files across operating systems.
- Locating the user’s Documents, Downloads, or Desktop folders portably.
- Following XDG Base Directory conventions on Linux without hardcoding
~/.config. - Writing state or data files to the OS-appropriate location for a CLI or desktop app.
Under The Hood
Architecture — The entire crate lives in a single ~6.5 KB lib.rs exposing two structs. AppDirs::new(name, xdg-style) computes cache/config/data/state paths by dispatching on the target OS via conditional compilation, applying the platform’s directory spec; UserDirs::new() resolves the standard user folders the same way. Each field is a PathBuf the caller can use directly.
Tech Stack — Pure Rust with a minimal dependency surface, using cfg(target_os = ...) to select the correct behavior for Linux/*BSD, macOS, and Windows. MIT-licensed. The implementation encodes the freedesktop XDG specs, Apple’s file-system guidelines, and the Windows Known Folder IDs.
Code Quality — Small and self-contained, the crate includes inline #[test] coverage in lib.rs and a documented, example-driven README. It has been stable since its last 0.3.0 release in 2020 and is essentially feature-complete for its narrow purpose, though no longer actively developed.
API Design — The API is about as approachable as possible: construct AppDirs with an app name (and a boolean for XDG-style layout) or UserDirs with no arguments, then read the fields you need. There is no configuration ceremony or trait plumbing, so the learning curve is essentially zero for anyone who has used a paths library before.