Skip to content

Get the module path of the caller in a proc_macro

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

Shizcow/caller_modpath

Repository files navigation

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
    );
}

About

Get the module path of the caller in a proc_macro

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages