Macromancy: an introduction to Rust macros
summary
Shows that Rust macros actually generate concrete code: uses macro_rules! patterns, hygiene rules and dollar_crate to avoid qualification pain, and combines declarative and procedural approaches. Debugging uses the compiler pretty expansion, unstable trace_macros and stringify traces; recursion hits a practical limit (bumped from 64 to 128 during work). Demonstrates a real build: lapa an AMQP client generated from XML via Handlebars templates and cookie_factory macros, which compiles and runs after refactoring recursion-heavy parts.
AI-written summary · about
chapters (10)
- 0:00Introduction
- 1:55Why use macros
- 6:07Hygiene
- 7:23Repetition
- 8:11Importing macros
- 10:02Macro match
- 13:30Macro wrap
- 15:24Macros
- 18:50Macro passers
- 21:15Conclusion
related talks
39mRust metaprogramming - macro_rules! beyond basics
24mMacros for a More Productive Rust
31mFunctional programming guerilla in the land of Rust
25m"Eternal Sunshine of the Rustfmt'ed Mind"
28mA gentle introduction to procedural macros
27mParsing Rust code considered harmful
29mLearning Rust by accident
21mProving macro expansion with expandable
