2 Declarative macros

This chapter covers

  • Writing declarative macros
  • Avoiding boilerplate and duplication, implementing newtypes, writing simple domain specific languages, and composing functions
  • Understanding the lazy_static crate

We will start this book in easy mode with declarative macros. These macros have a syntax that will immediately remind you of pattern matching, with a combination of matchers and transcribers. The matchers contain what you want to match against; the transcriber has the code you will generate when you find that match. It’s just that simple.

Get Write Powerful Rust Macros now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.