2 releases

0.1.1 Mar 13, 2021
0.1.0 Mar 13, 2021

#1803 in Development tools

MIT/Apache

13KB
186 lines

caller_modpath

crates.io docs.rs

This crates allows for getting the module path of the caller within a #[proc_macro_attribute].

For more information, read the docs.

Example

The simplest example is as follows:

#[caller_modpath::expose_caller_modpath]
#[proc_macro_attribute]
pub fn test(_attr: TokenStream, _input: TokenStream) -> TokenStream {
    let modpath: String = proc_macro::Span::caller_modpath();
    // now do something with it. For example, just panic to have the compiler display the result:
    panic!(
        "module path of call site: {}",
        modpath
    );
}

Dependencies

~1.7–2.6MB
~50K SLoC