A cross-platform Rust library for managing application data directories on Windows, macOS, and Linux.
The app_data crate provides a simple and standardized way to manage application data directories across different platforms. It automatically handles platform-specific directory conventions and ensures directories are created when needed.
- ✅ Cross-platform support (Windows, macOS, Linux)
- ✅ Automatic directory creation
- ✅ Local and system directory modes
- ✅ Custom error types with detailed messages
- ✅ Zero dependencies (only uses standard library)
The AppData directory follows these principles:
- Default behavior: Searches for
datadirectory under the startup path - Fallback: If the
datadirectory doesn't exist under the startup path, createsdatadirectory in the system user directory - Force local mode: When
force_localis enabled, always creates directories in the startup path
- Data:
%APPDATA%\app_name
- Data:
~/Library/Application Support/app_name
- Data:
$XDG_DATA_HOME/app_nameor~/.local/share/app_name
use app_data::AppData;
// Create with default settings
let app_data = AppData::default();
// Or specify application name
let app_data = AppData::new("my_app");
// Get data directory (creates if not exists)
let data_dir = app_data.ensure_data_dir()?;
println!("Data directory: {}", data_dir.display());
// Get file path in data directory
let config_file = app_data.get_file_path("config.json")?;use app_data::AppData;
// Force creation in startup directory
let app_data = AppData::with_force_local("my_app", true);
let data_dir = app_data.ensure_data_dir()?;
// Creates: ./data/use app_data::{AppData, AppDataError};
match app_data.ensure_data_dir() {
Ok(dir) => println!("Directory: {}", dir.display()),
Err(AppDataError::EnvVarNotFound(var)) => {
eprintln!("Environment variable {} not found", var);
}
Err(AppDataError::IoError(msg)) => {
eprintln!("IO error: {}", msg);
}
Err(AppDataError::CurrentDirError(msg)) => {
eprintln!("Failed to get current directory: {}", msg);
}
}See the examples/ directory for more complete examples.
MIT