This session, we walk through procedural macros, showing some of the great tooling available like cargo expand for understanding the code generated, and the crates used for writing our own.
We cover expanding other peoples macros, creating our own very simple derive macros, and building up more complex macros using repeat patterns in quote. We also cover basic error reporting, making use of item spans to ensure we report the errors in the correct place.
This talk is a follow on from a previous talk on declarative macros: https://youtu.be/ncm4gk3Lj9E
Useful links:
- Proc macro workshop - https://github.com/dtolnay/proc-macro-workshop
- Blog on testing proc macros - https://ferrous-systems.com/blog/testing-proc-macros/
- Crust of Rust Proc Macros videos - https://www.youtube.com/watch?v=geovSK3wMB8
- Jetbrains Proc Macros under the hood blog posts (parts i & ii) https://blog.jetbrains.com/rust/2022/03/18/procedural-macros-under-the-hood-part-i/
Presenter(s): Ciara
Meetup info:
This was a recording of a meetup on 10th August 2022. Join our meetup group for more information about future events: https://www.meetup.com/rust-and-c-plus-plus-in-cardiff/
You can also find us on discord, drop us a message to be sent the link
Big thank you to Esri for sponsoring our meetup page