The Little Book of Rust Macros

Note: This is a continuation of Daniel Keep's Book which has not been updated since the early summer of 2016, adapted to make use of mdBook.

View the rendered version here and the repository here.

This book is an attempt to distill the Rust community's collective knowledge of Rust macros, Macros by Example to be precise. As such, both additions (in the form of pull requests) and requests (in the form of issues) are welcome. The original Little Book of Rust Macros has helped me immensely with understanding Macros by Example style macros while I was still learning the language. Unfortunately, the author of the book has since left the project untouched, while the Rust language as well as it's macro-system keeps evolving. Which is why I wanted to revive the project and keep it up to date with current Rust helping other newcomers understand macros, a part of the language a lot of people seem to have trouble with.

This book expects you to have basic knowledge of Rust, it will not explain language features or constructs that are irrelevant to macros. No prior knowledge of macros is assumed. Having read and understood the first seven chapters of the Rust Book is a must, though having read the majority of the book is recommended.


Thanks to Daniel Keep for the original work and thanks to the following people for suggestions and corrections to the original: IcyFoxy, Rym, TheMicroWorm, Yurume, akavel, cmr, eddyb, ogham, and snake_case.


This work inherits the licenses of the original, hence it is licensed under both the Creative Commons Attribution-ShareAlike 4.0 International License and the MIT license.