🦀Building Rust Procedural Macros Without quote!: Introducing zyn
I've been writing proc macros for a while now. Derive macros for internal tools, attribute macros for instrumentation. And every time, the same two problems:quote!doesn't compose (you end up passingTokenStreamfragments through five layers of helper functions and writing hundreds ofletstatements), and debugging generated code meanscargo expandand then squinting at unformatted token output hoping something jumps out.
Because of this I ended up writing the same helper methods, composite AST parsing and tokenizing types, extractors etc. I would have to copy these from project to project as needed, and eventually just decided to publish a crate so I never have to do it again.
So I built zyn — a proc macro framework with a template language, composable components, and compile-time diagnostics.
I wrote the debug system after spending two days on a bug where a generated impl block was missing a lifetime bound. cargo expand spat out 400 lines of tokens and I couldn't find it, so I built a debug system.