xdir 0.1.0

Platform-agnistic standard directory locations
Documentation
  • Coverage
  • 100%
    7 out of 7 items documented1 out of 7 items with examples
  • Size
  • Source code size: 25.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.25 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 12s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • kaplanz/xdir
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • kaplanz

xdir

latest version dependency status documentation license

About

This crate provides a minimal and opinionated library for retrieving platform-agnostic XDG-compliant standard locations of directories. Notably, this crate will always yield the same locations for subdirectories of the user's home regardless of platform-specific conventions, which is often more consistent with what users would expect from a command-line application.

If you are building an application that strictly follows the platform's conventions, the dirs crate provides platform-specific locations.

Usage

xdir provides a minimal API to return the standard location of a given directory. This allows users to configure where they would like certain files to be stored using environment variables as per the XDG Base Directory Specification.

For example, to get the configuration file of an application:

fn config() -> PathBuf {
    xdir::config()
        // Append the application name to the path to avoid cluttering the
        // general config directory.
        .map(|path| path.join("myapp"))
        // If the standard path could not be found (e.g.`$HOME` is not set),
        // default to the current directory.
        .unwrap_or_default()
        // Finally, append the config file to the directory path.
        .join("config.toml")
}

License

This project is dual-licensed under both MIT License and Apache License 2.0. You have permission to use this code under the conditions of either license pursuant to the rights granted by the chosen license.