macron-path

Crates.iomacron-path
lib.rsmacron-path
version0.1.3
created_at2025-07-02 13:53:14.127086+00
updated_at2025-11-29 14:33:48.745416+00
descriptionCreates a new instance of PathBuf
homepage
repositoryhttps://github.com/fuderis/rs-macron/tree/main/macron-path
max_upload_size
id1735085
size12,346
Bulat Sh. (fuderis)

documentation

README

githubcrates-iodocs-rs

PathBuf 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:

  • 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").

Examples:

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());

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.

Commit count: 15

cargo fmt