xdgdir 0.8.0

Resolves paths according to the XDG Base Directory Specification
Documentation
  • Coverage
  • 100%
    14 out of 14 items documented1 out of 5 items with examples
  • Size
  • Source code size: 27.22 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 412.22 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • pyk/xdgdir
    1 0 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pyk

xdgdir

xdgdir helps you to resolves paths according to the XDG Base Directory Specification.

  • Zero I/O: The library performs no filesystem operations. It is a pure path resolver, making it fast, predictable, and suitable for any context, including async runtimes.
  • Spec Compliant: Correctly handles environment variables, empty variables, and default fallbacks as defined by the spec.
  • Simple API: Provides a minimal, ergonomic API for the most common use cases.

Getting started

Add xdgdir to your project's dependencies:

cargo add xdgdir

Usage

To get the set of directories for your specific application, use BaseDir::new().

use xdgdir::BaseDir;

fn main() {
    let dirs = BaseDir::new("my-app").unwrap();

    println!("Config file should be in: {}", dirs.config.display());
    // -> /home/user/.config/my-app
    println!("Data files should be in: {}", dirs.data.display());
    // -> /home/user/.local/share/my-app
}

To get the raw, non-application-specific base directories, use BaseDir::global().

use xdgdir::BaseDir;

fn main() {
    let global_dirs = BaseDir::global().unwrap();

    println!("Default user config dir: {}", global_dirs.config.display());
    // -> /home/user/.config
    println!("User executables dir: {}", global_dirs.bin.display());
    // -> /home/user/.local/bin
}

License

This project is licensed under the MIT License.