macron-path

Crates.iomacron-path
lib.rsmacron-path
version0.1.2
created_at2025-07-02 13:53:14.127086+00
updated_at2025-07-18 05:41:55.795492+00
descriptionCreates a new instance of PathBuf
homepage
repositoryhttps://github.com/fuderis/rs-macron/tree/main/macron-path
max_upload_size
id1735085
size10,946
Bulat Sh. (fuderis)

documentation

README

githubcrates-iodocs-rs

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.

Commit count: 15

cargo fmt