Skip to Content
Rust for Rustaceans
book

Rust for Rustaceans

by Jon Gjengset
December 2021
Intermediate to advanced
280 pages
8h 43m
English
No Starch Press
Content preview from Rust for Rustaceans

7 Macros

Macros are, in essence, a tool for making the compiler write code for you. You give the compiler a formula for generating code given some input parameters, and the compiler replaces every invocation of the macro with the result of running through the formula. You can think of macros as automatic code substitution where you get to define the rules for the substitution.

Rust’s macros come in many different shapes and sizes to make it easy to implement many different forms of code generation. The two primary types are declarative macros and procedural macros, and we will explore both of them in this chapter. We’ll also look at some ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rust in Action

Rust in Action

Tim McNamara
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols
Effective Rust

Effective Rust

David Drysdale
Command-Line Rust

Command-Line Rust

Ken Youens-Clark

Publisher Resources

ISBN: 9781098129828