| Crates.io | abs-file-macro |
| lib.rs | abs-file-macro |
| version | 0.1.2 |
| created_at | 2025-03-03 12:48:56.660693+00 |
| updated_at | 2025-03-03 13:59:53.13673+00 |
| description | A macro that returns the absolute file path of the Rust source file in which it is invoked. |
| homepage | |
| repository | https://github.com/jzombie/rust-abs-file-macro |
| max_upload_size | |
| id | 1575522 |
| size | 11,413 |
| 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.
cargo add abs-file-macro
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
);
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.
MIT License (c) 2025 Jeremy Harris.