3 releases
new 0.1.2 | Mar 3, 2025 |
---|---|
0.1.1 | Mar 3, 2025 |
0.1.0 | Mar 3, 2025 |
#552 in Rust patterns
520 downloads per month
7KB
abs-file-macro
OS | Status |
---|---|
Ubuntu-latest | |
macOS-latest | |
Windows-latest |
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:
-
As part of the full workspace
cargo test --workspace
This verifies that the macro functions correctly across all workspace members.
-
Within an individual workspace member
cd test-workspace-1 cargo test
This helps catch cases where path resolution might differ based on the working directory.
License
MIT License (c) 2025 Jeremy Harris.