Write Powerful Rust Macros, Video Edition

Write Powerful Rust Macros, Video Edition

English | MP4 | AVC 1280×720 | AAC 44KHz 2ch | 7h 15m | 1.11 GB

An example-driven, step-by-step guide to success with Rust macros.

In Write Powerful Rust Macros you’ll learn how to use these amazing metaprogramming tools to push Rust to its full potential. This hands-on guide takes you from the absolute basics to advanced macro techniques, exploring Rust macros through interesting and engaging examples.

Inside Write Powerful Rust Macros you’ll discover:

  • Writing declarative macros
  • Procedural macros
  • Reading and debugging macro code
  • Improving the type system with newtypes and zero-sized types
  • How common Rust libraries use macros

Write Powerful Rust Macros teaches you how to write, test, debug, and publish macros for Rust. It’s perfect for Rust practitioners who want to master this powerful development technique. Build your knowledge chapter-by-chapter. You’ll start with declarative macros before diving into the real power: procedural macros that can generate code, augment data structures, and even create domain-specific languages.

Macros are one of Rust’s most important and powerful tools. Although notoriously challenging, this metaprogramming technique has a big payoff. Using macros to generate new Rust code at compile-time can save you hours of tedious coding with negligible runtime performance impact. This book shows you exactly how to master this Rust superpower.

Write Powerful Rust Macros opens up the world of macros to intermediate Rust programmers. You’ll start with declarative macros to get the basics under your belt. Then, you’ll advance to procedural macros as you automatically generate a builder, learn to create your own domain-specific languages, and more. As you go, you’ll develop practical skills like testing macros, integrating macros with crates, and even sharing your macros with other developers.

What’s Inside

  • How Rust libraries use macros
  • Reading and debugging macro code
  • newtypes and the type state pattern
Table of Contents

1 Going meta
2 What is metaprogramming
3 Metaprogramming in Rust
4 Approach of this book
5 Summary
6 Declarative macros
7 Use cases
8 From the real world
9 Exercises
10 Summary
11 A Hello, World procedural macro
12 Analyzing the procedural macro setup
13 Generating output
14 Experimenting with our code
15 cargo expand
16 The same macro without syn and quote
17 From the real world
18 Summary
19 Making fields public with attribute macros
20 Attribute macros vs. derive macros
21 First steps in public visibility
22 Getting and using fields
23 Possible extensions
24 More than one way to parse a stream
25 Even more ways to develop and debug
26 From the real world
27 Summary
28 Hiding information and creating mini-DSLs with function-like macros
29 Debugging by writing normal code
30 Composing
31 Anything you can do, I can do better
32 From the real world
33 Summary
34 Testing a builder macro
35 Fleshing out the structure of our setup
36 Adding white-box unit tests
37 Black-box unit tests
38 What kinds of unit tests do I need
39 Beyond unit tests
40 From the real world
41 Summary
42 From panic to result Error handling
43 Pure and impure functions
44 Alternatives to exceptions
45 Rust s Result and panics
46 Setup of the panic project
47 Mutable or immutable returns
48 Getting results
49 Don t panic
50 Error-handling flavors
51 From the real world
52 Exercises
53 Summary
54 Builder with attributes
55 Alternative naming for attributes
56 Sensible defaults
57 A better error message for defaults
58 Build back better
59 Avoiding scattered conditionals
60 Attribute tokens and attributes
61 Other attributes
62 From the real world
63 Summary
64 Writing an infrastructure DSL
65 How our DSL works
66 Parsing our input
67 Two alternative parsing approaches
68 Actually creating the services
69 The two AWS clients
70 Errors and declarative macros
71 The right kind of testing
72 From the real world
73 Summary
74 Macros and the outside world
75 Adding another macro
76 Features
77 Documenting a macro
78 Publishing our macro
79 From the real world
80 Where to go from here
81 Summary
82 Exercise solutions

Homepage