Intro to Rust Macros


First Macro: timeit!

Jul - 2020 (~7 minutes read time)

This series serves as a practical (but not-exhaustive) introduction to declarative macro_rules!. I've put together some Rust macro examples to show how macros can be helpful for improving ergonomics around repetitive or error-prone tasks. The examples cover some great scenarios for macros like:

  • Print out the time a block of code takes to execute
  • Adding retries around intermittently fallible code
  • Making data structure initialization easier for common options