liveBook · Manning

What you will learn in Write Powerful Rust Macros

by Sam Van Overmeire

Chapter by chapter

Chapter 1: Going meta

1.1 A day in the life of a Rust developer · 1.2 What is metaprogramming? · 1.3 Metaprogramming in Rust · 1.3.1 Macro galore · 1.3.2 Appropriate use cases · 1.3.3 Unfit for purpose: When not to use macros · 1.4 Approach of this book · 1.5 Exercise · 1.6 Summary

What you learn in chapter 1 →

Chapter 2: Declarative macros

2.1 Creating vectors · 2.1.1 Syntax basics · 2.1.2 Declaring and exporting declarative macros · 2.1.3 The first matcher explained · 2.1.4 nonemtpy matchers · 2.2 Use cases · 2.2.1 Varargs and default arguments · 2.2.2 More than one way to expand code · 2.2.3 Newtypes · 2.2.4 DSLs · 2.2.5 Composing is easy · 2.2.6 Currying, on the other hand . . . · 2.2.7 Hygiene is something to consider as well · 2.3 From the real world · 2.4 Exercises · 2.5 Summary

What you learn in chapter 2 →

Chapter 3: A “Hello, World” procedural macro

3.1 Basic setup of a procedural macro project · 3.2 Analyzing the procedural macro setup · 3.3 Generating output · 3.4 Experimenting with our code · 3.5 cargo expand · 3.6 The same macro—without syn and quote · 3.7 From the real world · 3.8 Exercises · 3.9 Summary

What you learn in chapter 3 →

Chapter 4: Making fields public with attribute macros

4.1 Setup of an attribute macro project · 4.2 Attribute macros vs. derive macros · 4.3 First steps in public visibility · 4.4 Getting and using fields · 4.5 Possible extensions · 4.6 More than one way to parse a stream · 4.6.1 Delegating tasks to a custom struct · 4.6.2 Implementing the Parse trait · 4.6.3 Going low, low, low with cursor · 4.7 Even more ways to develop and debug · 4.8 From the real world · 4.9 Exercises · 4.10 Summary

What you learn in chapter 4 →

Chapter 5: Hiding information and creating mini-DSLs with function-like macros

5.1 Hiding information · 5.1.1 Setup of the information-hiding macro · 5.1.2 Recreating the struct · 5.1.3 Generating the helper methods · 5.2 Debugging by writing normal code · 5.3 Composing · 5.4 Anything you can do, I can do better · 5.5 From the real world · 5.6 Exercises · 5.7 Summary

What you learn in chapter 5 →

Chapter 6: Testing a builder macro

6.1 Builder macro project setup · 6.2 Fleshing out the structure of our setup · 6.3 Adding white-box unit tests · 6.4 Black-box unit tests · 6.4.1 A happy path test · 6.4.2 A happy path test with an actual property · 6.4.3 Testing enables refactoring · 6.4.4 Further improvements and testing · 6.4.5 An alternative approach · 6.4.6 Unhappy path · 6.5 What kinds of unit tests do I need? · 6.6 Beyond unit tests · 6.7 From the real world · 6.8 Exercises · 6.9 Summary

What you learn in chapter 6 →

Chapter 7: From panic to result: Error handling

7.1 Errors and control flow · 7.2 Pure and impure functions · 7.3 Alternatives to exceptions · 7.4 Rust’s Result and panics · 7.5 Setup of the panic project · 7.6 Mutable or immutable returns · 7.7 Getting results · 7.8 Don’t panic · 7.8.1 Changing the panic into a Result · 7.8.2 Debugging observations · 7.9 Error-handling flavors · 7.9.1 Using syn for error handling · 7.9.2 Using proc_macro_error for error handling · 7.9.3 Deciding between syn and proc_macro_error · 7.10 From the real world · 7.11 Exercises · 7.12 Summary

What you learn in chapter 7 →

Chapter 8: Builder with attributes

8.1 A rename attribute · 8.1.1 Testing the new attribute · 8.1.2 Implementing the attribute’s behavior · 8.1.3 Parsing variations · 8.2 Alternative naming for attributes · 8.3 Sensible defaults · 8.4 A better error message for defaults · 8.5 Build back better · 8.5.1 Avoiding illegal states and the type state pattern · 8.5.2 Combining the builder pattern with type state · 8.6 Avoiding scattered conditionals · 8.7 Attribute tokens and attributes · 8.8 Other attributes · 8.9 From the real world · 8.10 Exercises · 8.11 Summary

What you learn in chapter 8 →

Chapter 9: Writing an infrastructure DSL

9.1 What is IaC? What is AWS? · 9.2 How our DSL works · 9.3 Parsing our input · 9.3.1 Project setup and usage examples · 9.3.2 Implementing the Parse trait for our structs · 9.4 Two alternative parsing approaches · 9.4.1 Using Punctuated with a custom struct · 9.4.2 Using Punctuated with a custom enum and builder · 9.5 Actually creating the services · 9.6 The two AWS clients · 9.7 Errors and declarative macros · 9.8 The right kind of testing · 9.9 From the real world · 9.10 Exercises · 9.11 Summary

What you learn in chapter 9 →

Chapter 10: Macros and the outside world

10.1 A function-like configuration macro · 10.1.1 Macro project structure · 10.1.2 Code overview · 10.1.3 Using full paths · 10.2 Adding another macro · 10.3 Features · 10.4 Documenting a macro · 10.5 Publishing our macro · 10.6 From the real world · 10.7 Where to go from here · 10.8 Exercises · 10.9 Summary

What you learn in chapter 10 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.