Overview of xdgdir

Here's what xdgdir is, why you'd use it, and the reason I made it.

I built a small Rust crate called xdgdir. It’s a simple tool that helps you find the correct directories for your application’s config, data, and cache files based on the XDG Base Directory Specification.

I needed a library like this for my own projects, and I had a few key goals in mind when I wrote it.

How it Works

The most common thing you’ll do is get a set of paths for your application. You just give xdgdir your app’s name, and it figures out the rest.

Here’s a quick example.

Rust
use xdgdir::BaseDir;

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

    // Prints something like /home/user/.config/my-app
    println!("Config files go here: {}", dirs.config.display());

    // Prints something like /home/user/.local/share/my-app
    println!("Data files go here: {}", dirs.data.display());

    // Prints something like /home/user/.cache/my-app
    println!("Cache files go here: {}", dirs.cache.display());
}

It’s important to know that xdgdir does not create these directories for you. It only tells you where they should be. It’s up to you to create them if they don’t exist.