A picnic scene featuring Osaka, Sakaki, and Chiyo toys, sitting out in a grassy area someplace, with various fruits.

Declarative Macros in Rust: A Simple and Practical Introduction

Macros are commonly presented as simple “text substitution” language features. But the way they’re implemented can change your experience using with them. The simplicity of a text-replacement-style implementation (sometimes referred to as C-style macros) can often lead to surprising and counter-intuitive results. As such, those feel simple to learn, but difficult to master and use safely. In Rust, however, macros work in a way that may be unfamiliar to many. They are recognized and processed during the compiler’s parsing phase. That can make them do some powerful things, but it also can make them a little hard to learn and understand initially. Since macros are a huge topic, there’s no way I’m going to be able to cover all of it in one article. So we’re only going to focus on a brief introduction to macros, as well as defining and using declarative macros. Updates: - 2026/10/08 - added an introduction covering what macros are, based on feedback from the Rust Users Forums.
Read More...
A Chiyo toy from Azumanga Daioh standing at the front of a classroom.

How to Organize Rust Modules for Maintainability

Today I’d like to talk a bit about how I like to organize my Rust projects. In particular, I’d like to talk about modules (you cannot talk about project organization without talking about modules). First, I’ll define what modules are, and give a brief explanation for how they work. After that, I’ll explain my recommended approach for organizing modules in Rust.
Read More...