I'm using the syn
crate and running into an issue when attempting to override the visit_macro_mut
function in order to visit and mutate inputs to macros (in a non-procedural macro context). I tried using the parse_macro_input!
macro at first, but the documentation for it seems to imply that that macro must be called in a function that receives and returns a TokenStream
, which I'm not doing. So I have something like this:
fn visit_macro_mut(&mut self, node: &mut Macro) {
let tokens = node.tokens.clone();
let tokens = tokens.into();
let parsed = Punctuated::<Expr, Token![,]>::parse_terminated(tokens).unwrap();
}
However the compiler complains about the tokens.into()
call, which I'm using to attempt to transform tokens: TokenStream
into tokens: ParseBuffer
. It reports back the following:
the trait bound `&syn::parse::ParseBuffer<'_>:
std::convert::From<proc_macro2::TokenStream>` is not satisfied
`std::convert::From<proc_macro2::TokenStream>` is implemented for `&mut syn::parse::ParseBuffer<'_>`, but not for `&syn::parse::ParseBuffer<'_>`
So I'm not sure how to coerce tokens
in order to get this to work, or if there's a different way in which I should be going about this.