DMACROS

image

We’ve used macros like println! throughout this book but haven’t fully explored what a macro is and how it works. This appendix explains macros as follows:

  • What macros are and how they differ from functions
  • How to define a declarative macro to do metaprogramming
  • How to define a procedural macro to create custom derive traits

We’re covering the details of macros in an appendix because they’re still evolving in Rust. Macros have changed and, in the near future, will change at a quicker rate than the rest of the language and standard library since Rust 1.0, so this section is more likely to become out-of-date than the rest of the book. ...

Get The Rust Programming Language 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.