I was trying a simple procedural macro following the example from the documentation, more specifically:
#[proc_macro_attribute]
pub fn show_streams(attr: TokenStream, item: TokenStream) -> TokenStream {
println!("attr: \"{}\"", attr.to_string());
println!("item: \"{}\"", item.to_string());
item
}
It shows how this macro prepends the function with the two prints. However, I've tried to reproduce an even simpler case, with my macro being:
#[proc_macro_attribute]
pub fn test_macro(_: TokenStream, item: TokenStream) -> TokenStream {
println!("Macro start");
item
}
I then run my main function of the crate:
use test_macro::test_macro;
#[test_macro]
fn main() {
println!("yup");
}
And no prints appear.
I thought maybe the main
method can't have macros attached, so I tested on another function and it didn't work either.
I'm pretty confused, what am I missing?