-
Book Overview & Buying
-
Table Of Contents
Rust for C++ Developers
By :
Procedural macros in Rust allow for extremely powerful code-generation abilities, at the cost of significantly greater development complexity than declarative macros. These macros are at the heart of some of the most powerful and compelling features in the crate ecosystem. This includes ergonomic serialization using crates such as serde_derive and intuitive command-line parsing using crates such as clap and argp.
In this section, we'll explore the different types of procedural macros Rust offers and construct a short example for each.
Rust currently supports three separate types of procedural macros: custom derives, custom attributes, and function-like procedural macros. We'll investigate these three types of procedural macros in the order in which a programmer is most likely to encounter them. But first, we'll begin by looking at the properties shared by all three types.
One of the most notable...