pub fn exe_dir() -> &'static PathExpand description
Get the executable’s directory.
Recommended for most applications. Returns the directory containing the current executable. Use this for building custom paths or integrating with other APIs.
§Performance
- First call: Determines and caches the executable directory
- Subsequent calls: Returns cached result immediately (no system calls)
- Thread-safe: Safe to call from multiple threads
§Panics
Panics if executable location cannot be determined (extremely rare):
std::env::current_exe()fails- Executable path is empty (system corruption)
After first successful call, never panics (uses cached result).
§Examples
use app_path::exe_dir;
use std::fs;
// Basic usage
let exe_directory = exe_dir();
println!("Executable directory: {}", exe_directory.display());
// Build custom paths
let config = exe_dir().join("config.toml");
let data_dir = exe_dir().join("data");
// Use with standard library
if config.exists() {
let content = fs::read_to_string(&config)?;
}
fs::create_dir_all(&data_dir)?;