Tris explains that Rust macros are powerful compile-time code execution tools, not just keystroke savers, using procedural macros like SQLx to validate code and generate precise errors.
In this video, Tris introduces macros as his favorite Rust language feature, arguing that most discussions overlook their true power: compile-time code execution, not just saving keystrokes. He contrasts Rust’s macros with C’s simpler text substitution, explaining that macro_rules! works like match statements evaluated during compilation to generate code. The video then highlights procedural macros as the "ultimate boilerplate killer," capable of running arbitrary code at compile time—exemplified by SQLx's query!, which validates SQL against a real database and surfaces errors as precise compiler messages. Ultimately, Tris outlines the four macro forms in Rust—declarative macros, custom derives, attribute-like macros, and function-like macros—framing them as a gateway to a far richer metaprogramming world.
▶ 0:01 Tris introduces the No Boilerplate channel, focused on fast, technical videos, and sets up macros as the topic and his favorite language feature.
▶ 0:23 Most macro coverage misses the biggest power: compile-time code execution, instead focusing only on DRY code or saving keystrokes.
▶ 0:35 This limited view persists because most languages can't run arbitrary code at compile time; Tris uses the cave analogy to show Rust macros offer a far richer world.
macro_rules! macros are a more powerful, code-generating form.macro_rules! macros are essentially match statements executed at compile time, inserting code that then runs normally at runtime.num-traits is a private macro that repeats the same impl block 15 times to reduce code duplication for library authors.T (a type) and Min/Max (type expressions), passed in this case as u8::MIN and u8::MAX.$-notation to substitute parameters into code, and the compiler's macro expansion shows the pasted-in intermediate code—similar to a templating language, but at compile time.macro_rules! for simple syntax rewriting, and procedural macros that can run arbitrary code at compile time and act as “the ultimate boilerplate killer.”query!, which tests real SQL against a dev database in a transaction and turns database errors into precise Rust compiler errors—no extra plugins needed.Load the full timestamped transcript on demand and click any time to jump in the video.