Expand description
§File Path Macro
A macro for ergonomic and safe construction of file and directory paths in Rust, with context-aware resolution.
- Supports both string literals and formatted paths with arguments.
- Automatically determines whether to allow a path relative to the current working directory, the executable directory, or the user data directory.
P.S. More useful macros are available in the macron package.
§Features
- Relative to current working directory: If the path does not start with / or , it is resolved relative to the current working directory (std::env::current_dir()).
- Relative to executable’s directory: If the path starts with / or , it is resolved relative to the directory where the executable resides (std::env::current_exe()).
- Supports formatting: You can use string formatting just like with the standard format! macro.
§Examples:
use macron_path::path;
// Path relative to the current working directory
let relative_path = path!("foo/bar");
// Path relative to the application executable's directory
let app_root_path = path!("/foo/bar");
// Path relative to the user data directory for saving applications data
let user_data_path = path!("$/foo/bar");
// Supports string formatting
let fmt_path = path!("foo/{}", "bar");§Notes:
-
Windows: Both / and \ are supported as path separators.
-
Linux/macOS: Only / is treated as a directory separator. For best results, use / or build paths using the macro or standard library methods.
-
Always use the path!: macro to avoid issues with separators and path resolution differences across platforms.
§Licensing:
Distributed under the MIT license.
§Feedback:
You can contact me via GitHub or send a message to my Telegram @fuderis.
This library is actively evolving, and your suggestions and feedback are always welcome!
P.S. More useful macros are available in the macron package.
Macros§
- path
- Creates a new instance of PathBuf