abs-file-macro 0.1.0

A macro that returns the absolute file path of the Rust source file in which it is invoked.
Documentation
  • Coverage
  • 50%
    1 out of 2 items documented1 out of 1 items with examples
  • Size
  • Source code size: 10.12 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 129.5 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 8s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • jzombie/rust-abs-file-macro
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • jzombie

abs-file-macro

made-with-rust crates.io Documentation MIT licensed

OS Status
Ubuntu-latest Ubuntu Tests
macOS-latest macOS Tests
Windows-latest Windows Tests

A macro that returns the absolute file path of the Rust source file in which it is invoked.

This macro ensures that the correct absolute path is resolved, even when used within a Cargo workspace or a nested crate. It prevents issues with duplicated path segments by properly handling the crate root.

Install

cargo add abs-file-macro

Usage

Example

use abs_file_macro::abs_file;

let path = abs_file!();

assert!(
    std::fs::metadata(&path).is_ok(),
    "abs_file!() should point to a real file, but {:?} does not exist",
    path
);

Testing

To ensure correctness, test this macro in two ways:

  1. As part of the full workspace

    cargo test --workspace
    

    This verifies that the macro functions correctly across all workspace members.

  2. Within an individual workspace member

    cd test-workspace-1
    cargo test
    

    This ensures that the macro works independently within a single workspace member.

License

MIT License (c) 2025 Jeremy Harris.