I have created a function-like procedural macro. I call it with a declarative macro as parameter. I was hoping to find a way that the declarative macro is expanded before processing the procedural macro (or expand it inside the procedural macro). Example (code is also available at https://github.com/Jasperav/rec_macro):
Call site:
macro_rules! t {
($e:expr) => {
$e.to_string() + " I am a macro"
}
}
fn main() {
re!(t!("hi"));
}
Proc macro crate:
#[proc_macro_hack]
pub fn re(input: TokenStream) -> TokenStream {
panic!("{:#?}", input) // I can see "hi" and something like t!, but not the result of the macro expansion
}
Inside the panic
message, I see see that the declarative macro (t
) is inside. I just want the raw value of hi I am a macro
in this case (or some syn
type). In my case, the declarative macro should always expand to a &str
or String
.
Is it possible to expand t
before invoking re
, or to expand t
manually inside the proc macro? I want to see the result of the macro (in this case: "hi I am a macro") inside my proc functional like macro.
Thanks.