module_path_extractor
A small helper crate for proc macros that need to resolve module paths and module files from a call-site span.
What it provides
- Call-site file/line discovery via
get_source_info(). - Module path resolution via
find_module_path()orfind_module_path_in_file(). - Module root detection via
module_root_from_file(). - File-to-module-path helpers via
module_path_from_file()andmodule_path_from_file_with_root(). - Module-path-to-file mapping via
module_path_to_file().
Usage
use ;
let = get_source_info.expect;
let module_path = find_module_path.expect;
let root = module_root_from_file;
let module_path_with_root =
find_module_path_in_file.expect;
let module_file = module_path_to_file
.expect;
Notes
- This crate requires nightly because it uses
proc_macro_span. - Module root resolution assumes a standard Cargo layout with
src/.