| Crates.io | macron-path |
| lib.rs | macron-path |
| version | 0.1.3 |
| created_at | 2025-07-02 13:53:14.127086+00 |
| updated_at | 2025-11-29 14:33:48.745416+00 |
| description | Creates a new instance of PathBuf |
| homepage | |
| repository | https://github.com/fuderis/rs-macron/tree/main/macron-path |
| max_upload_size | |
| id | 1735085 |
| size | 12,346 |
A macro for ergonomic and safe construction of file and directory paths in Rust, with context-aware resolution.
P.S. More useful macros are available in the macron package.
Empty call: path!() returns PathBuf::new().
Executable prefix $: path!("$") → std::env::current_exe().
Executable directory $/: path!("$/foo/bar") → current_exe().parent().join("foo/bar").
Home directory ~/: path!("~/foo/bar") → $HOME/foo/bar (USERPROFILE on Windows).
User data directory %/:
| OS | Default Directory |
|---|---|
| Windows | C:/Users/User/AppData/Roaming/ |
| macOS | ~/Library/Application Support/ |
| Linux | ~/.local/share |
Formatting: path!("foo/{arg1}/{}", arg2).
Expressions: path!(some_path_var).
Plain paths: path!("foo/bar").
use macron_path::path;
// empty PathBuf:
let empty = path!();
// plain path (relative to CWD):
let relative = path!("foo/bar");
// executable path:
let exe_path = path!("$");
// executable directory:
let exe_dir_path = path!("$/config.toml");
// home directory:
let home_path = path!("~/Documents/file.txt");
// user data directory:
let data_path = path!("%/myapp/settings.json");
// formatting:
let user_path = path!("users/{}/docs", "alice");
let dynamic = path!("dir/{}", some_var.to_string());
Distributed under the MIT license.
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.