File:Crust of Rust- Declarative Macros.webm
Summary
Description |
English: In this second Crust of Rust video, we cover declarative macros, macro_rules!, by re-implementing the vec! macro from the standard library. As part of that, we cover not only how to write these, but some of the gotchas and tricks you'll run into, and some common use-cases.
You can find the final code at https://gist.github.com/jonhoo/ec57882a976a2d2a92b3138ea25cd45a, and the Little Book of Rust Macros at https://danielkeep.github.io/tlborm/book/index.html. 0:00:00 Introduction 0:01:35 The vec macro 0:04:08 The Little Book of Rust Macros 0:05:17 Macro syntax and hygiene 0:16:42 The empty vector 0:19:26 Non-empty vectors 0:25:50 Macros v2 0:26:34 Macro delimiters 0:27:54 Declarative vs procedural macros 0:30:15 Repeated macro arguments 0:39:49 Trailing commas 0:44:10 Why are macros useful? 0:47:29 Vector by repetition 0:51:02 Macro rules readability 0:52:00 Invalid macro inputs 0:54:52 Test that something doesn't compile 0:56:50 Tidying up the patterns 0:59:05 Reallocations for repetition constructor 1:04:08 Macro argument trait bounds 1:06:40 "use" hygiene in macros 1:08:28 The standard library pattern 1:10:20 The need for counting 1:11:38 Eager macro errors 1:13:00 Counting in macros 1:24:48 Other ways of counting 1:27:27 Ensuring count is computed at compile time 1:28:32 Hiding internal macro patterns 1:31:13 Other collection literals 1:33:00 Comparing against the std implementation You can watch the live version with comments at https://www.youtube.com/watch?v=UIY75ohrqKQ |
Date | |
Source | YouTube: Crust of Rust: Declarative Macros – View/save archived versions on archive.org and archive.todayCategory:Media from YouTube |
Author | Jon Gjengset |
Licensing

- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
![]() |
This file, which was originally posted to an external website, has not yet been reviewed by an administrator or reviewer to confirm that the above license is valid. See Category:License review needed for further instructions. |