Crate app_path

Source
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

§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 AppPath instances with optional environment variable overrides.

Structs§

AppPath
Creates paths relative to the executable location for portable applications.

Enums§

AppPathError
Error type for AppPath operations.

Functions§

exe_dir
Get the executable’s directory.
try_exe_dir
Get the executable’s directory (fallible).