So I have defined the following procedural macro:
#[proc_macro_attribute]
pub fn hello(attr: TokenStream, item: TokenStream) -> TokenStream {
println!("attr: {}", attr);
println!("item: {}", item);
item
}
then I apply this proc macro to a non-inline module:
// In file some_mod.rs
#![hello]
fn foo() {}
fn bar() {}
The output of the compiler indicates that the item passed to the proc macro hello
is mod some_mod;
, without any items in the module. however I want to do some modifications to the content of the module some_mod
.
I have figured out that inline module works:
mod some_mod {
#![hello]
fn foo() { }
fo bar() { }
}
The item passed to my proc macro is mod some_mod { fn foo() { } fn bar() { } }
.
But I will use my proc macro in a complex module hierarchy, I don't want to put all those modules in a single file.
Is there any way to make my proc macro get the content of the non-inline module?