xdgdir

Crates.ioxdgdir
lib.rsxdgdir
version0.8.0
created_at2025-09-15 13:41:31.802132+00
updated_at2025-09-15 13:41:31.802132+00
descriptionResolves paths according to the XDG Base Directory Specification
homepagehttps://github.com/pyk/xdgdir
repositoryhttps://github.com/pyk/xdgdir
max_upload_size
id1839973
size27,228
pyk (pyk)

documentation

https://docs.rs/xdgdir

README

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.

Commit count: 24

cargo fmt