Expand description
§app-path
Create portable applications that keep files together with the executable.
§Quick Start
use app_path::AppPath;
// Files relative to your executable
let config = AppPath::new("config.toml");
let database = AppPath::new("data/users.db");
let logs = AppPath::new("logs/app.log");
// Works like standard paths
if config.exists() {
let content = std::fs::read_to_string(&config)?;
}
// Create directories with clear intent
logs.ensure_parent_dirs()?; // Creates logs/ directory for the file
database.ensure_parent_dirs()?; // Creates data/ directory for the file§Key Features
- Portable: Relative paths resolve to executable directory
- System integration: Absolute paths work as-is
- Zero dependencies: Only standard library
- High performance: Static caching, minimal allocations
- Thread-safe: Concurrent access safe
§API Design
AppPath::new()- Recommended: Simple, infallible constructorAppPath::try_new()- Libraries: Fallible version for error handlingAppPath::with_override()- Deployment: Environment-configurable pathsAppPath::ensure_parent_dirs()- Files: Creates parent directories for filesAppPath::ensure_dir_exists()- Directories: Creates directories (and parents)exe_dir()- Advanced: Direct access to executable directory
§Panic Conditions
AppPath::new() and exe_dir() panic only if executable location cannot be determined:
std::env::current_exe()fails (extremely rare)- Executable path is empty (system corruption)
These represent unrecoverable system failures. For fallible behavior, use AppPath::try_new().
Macros§
- app_
path - Convenience macro for creating
AppPathinstances with optional environment variable overrides.
Structs§
- AppPath
- Creates paths relative to the executable location for portable applications.
Enums§
- AppPath
Error - Error type for AppPath operations.
Functions§
- exe_dir
- Get the executable’s directory.
- try_
exe_ dir - Get the executable’s directory (fallible).