Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Welcome to Macros in Rust

Welcome to the course on Macros in Rust. Macros are a powerful tool for meta-programming, allowing to abbreviate and generate code without runtime overhead.

In this course, we will cover:

  • What macros are and why they are useful.
  • The distinction between declarative and procedural macros.
  • How the compiler processes tokens and constructs syntax trees.
  • How to define Macros By Example and how they are matched, and expanded.
  • Advanced declarative macro techniques.
  • Macro hygiene and scoping.
  • How to write procedural macros, along with typical structure and patterns.

Schedule

Including 10 minute breaks, this session should take about 6 hours and 5 minutes. It contains:

SegmentDuration
What Is A Macro30 minutes
Macros In Rust30 minutes
Macros, Tokens, and Syntax15 minutes
Macros By Example1 hour
Declarative Macro Techniques1 hour
Hygiene15 minutes
Procedural Macros1 hour and 35 minutes