Expand description
Resolves paths according to the XDG Base Directory Specification.
§Overview
xdgdir
is a spec-compliant crate for locating user and system directories.
- 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.
§Examples
To get the set of directories for a specific application, use
BaseDir::new()
.
use xdgdir::BaseDir;
let dirs = BaseDir::new("my-app")?;
// Example output: /home/user/.config/my-app
println!("Config file should be in: {}", dirs.config.display());
// Example output: /home/user/.local/share/my-app
println!("Data files should be in: {}", dirs.data.display());
To get the raw, non-application-specific base directories, use
BaseDir::global()
.
§Errors
The library functions return Result<BaseDir, xdgdir::Error>
. Errors occur
if the environment is misconfigured according to the spec’s requirements.
Structs§
- BaseDir
- A struct containing resolved XDG directories, representing either a global or an application-specific context.
Enums§
- Error
- An error that can occur when resolving XDG base directories.