by zzzeek · 2w ago · 0 comments
This is happening in Python land as well. now that type annotations are a normal everyday thing we are doing a lot of code generation. Of course I'm sure how Rust does it is much better integrated and "correct" and all that but the Python thing of generating functions/classes/etc. on the fly is not quite the sole choice anymore for various reasons, and pep484 and related are making static code generation more feasible.
Not really. There are two different macro systems, one of them has you writing cryptic functional style pattern matching on expressions and the other just gives you a stream of tokens to parse yourself.
Neither of them lets you create types, functions or traits as objects like in Zig. You need to build Rust expressions that produce them and keep track of all the names while doing it. If the macro fails to put out valid code the user gets a confusing error, unless you make them use the nightly compiler. It's one level above C style string manipulation.
And did I mention that if your macro extends Rust syntax you need to pull in a third party Rust parser, because the one in the compiler is strictly internal?