Idiomatic way to parse generic arguments in a macro

I'm trying to write some macros (standard, not procedurla) that implement stuff for some types. The types have generic arguments, so they must be parsed and placed correctly by the macro in the impl section. Is there any standard/idiomatic way to do this? I found some ideas on StackOverflow, but I'm surprised there is no well-established technique.

BTW, I realize it's trivial with procedural macros.

There isn't.

It hasn't been tested in a long while, but here's a crate that implements some generics parsing macros. Specifically, it's a stable implementation of a proposed (but rejected) addition to the language from a ways back. There's more information in the root of the repository, including some scattered tests.

The one limitation I remember from this (aside from the complexity and how much of the recursion stack it eats up) was that it only worked for the 26 single-letter lifetimes. Since then, a lifetime matcher was added, so that should actually be solvable now.

As someone who loves abusing regular macros, here's my advice: do not use the above crate, just use proc macros. It's really, really not worth it. Not even remotely.

But if you're doing it to learn, knock yourself out. :slight_smile:

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.