Let's Write a Macro in Rust
hackeryarn.com·10h·
Discuss: Hacker News

Macros are required to do some very helpful things in Rust, but this isn’t an article about any of those things.

I became ennamored with macros many years ago when I read Practical Common Lisp and saw the implementation of a SQL DSL that works with built in data structures. The whole implementation took less than a screen of code and absolutely blew away my expectations of what it took to create DSLs.

In this article, I will try to share some of that excitement with you while using Rust’s macro system. Will this be the most practical and useful macro you can write? Absolutely not. I only hope to show you some possibilities of this powerful tool.

Prior art

Rust’s macros build on top of a long legacy of syntax macros primarily seen in the Lisp la…

Similar Posts

Loading similar posts...