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.
NOTE This chapter’s focus is a broad overview of declarative macros and their usage. This stands in contrast with the rest of this book, where we will focus on specific topics ...
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.