Is it possible to call another proc macro from a dependency crate and modify it's output in my own macro?
For example, wasmtime_component_macro
exports a bindgen
macro, can I modify it's output like this?
#[proc_macro]
pub fn my_bindgen(stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
let mut stream = wasmtime_component_macro::bindgen(stream);
// Modify the stream
// Return the modified stream
stream
}
This results in a compile error: expected function, found macro wasmtime_component_macro::bindgen
The original bindgen
proc macro is declared as a public function that takes and returns a TokenStream
:
#[proc_macro]
pub fn bindgen(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
bindgen::expand(&parse_macro_input!(input as bindgen::Config))
.unwrap_or_else(Error::into_compile_error)
.into()
}
So is it possible to call it with a token stream and get the token stream result?
Invoking the macro with !
and the stream
argument like this: let stream = wasmtime_component_macro::bindgen!(stream);
doesn't work.