Proc-macro-attribute: Create syn::Attribute from attribute arguments

I'm trying to (re)'create' a syn::Attribute within a proc-macro-attribute macro.
I'm wondering if I've missed some convenience functions/patterns because it appears to be quite complex.
As the playground example stand it seems now I have to implement TokenStream for MyAttr struct.

If it is necessary I can elaborate on the context/use-case but it feels like a distraction as a write it out.

A playground example of where I'm at is here:

Appreciate any hints or tips.

I'm not sure what you are expecting? Your type doesn't implement Into<TokenStream> (either directly or by means of a From impl), so you can't just .into() it an expect a TokenStream out. The conventional approach to making your own AST types printable is to implement quote::ToTokens, anyway.

Furthermore, I don't understand why you are reinventing the wheel. If you are trying to parse a tree of attributes into actionable domain types, use Darling.

Thanks @H2CO3, darling is indeed what I was looking for.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.