u/420goonsquad420in r/rust • Recommends
On “Talk to me about macros”
111K subscribers • 38 videos on Hallway
Advanced. Deep dive for people who know the field.
80K views7 years ago8 recommendations
Programming languagesSystems programmingRustCompilers and interpreters
Jon Gjengset walks through David Tolnay's procedural macro workshop, implementing a custom derive macro from scratch.
In this stream, we take a look at Rust's procedural macros. These are much more flexible than the declarative macros you get with the macro_rules! construct, and effectively allow you to write source-code transformations as a separate program. Take a look at doc.rust-lang.org/book/ch19-06-macros.html and doc.rust-lang.org/nightly/reference/procedural-macros.html for details. In particular, we follow David Tolnay's excellent proc-macro workshop from Rust Latam back in March 2019: github.com/dtolnay/proc-macro-workshop. The goal is to implement the custom derive(Builder) project (the first one listed). We managed to get all the way through and then some! For tools, we ended up relying quite heavily on David's github.com/dtolnay/syn and github.com/dtolnay/quote, as well as the very handy cargo-expand tool: github.com/dtolnay/cargo-expand. You can find the code over at github.com/jonhoo/proc-macro-workshop. Oh, and the issue with formatting doc comments we encountered at the end has already been fixed @ github.com/rust-lang/rustfmt/pull/3548 ! You can see the live version with comments at youtube.com/watch?v=0-sMn2fXYG4What people say. Highly recommended as a comprehensive, step-by-step guide to understanding and writing procedural macros in Rust.
u/420goonsquad420in r/rust • Recommends
On “Talk to me about macros”
u/WrongJudgment6in r/rust • Recommends
On “Where is the source / a *usable* reference/tutorial on metaprogramming?”
u/WhoisDavidin r/rust • Recommends
On “Procedural Macros: The Basics | blog.turbo.fish”
u/1668553684in r/rust • Recommends
On “Compiling into rust followed by rust compiler?”
u/trabe_lazyin r/rust • Recommends
On “Is there a simple proc-macro derive attributes example?”
u/fear_the_morrokin r/rust • Recommends
On “Resources for writing good proc-macros?”
u/MasterTextmanin r/rust • Recommends
On “Tablefy - my first crate!”