Skip to content

Macro Plan

That’s an intense study session! πŸš€ You can definitely get very comfortable with Rust macros in that time if you focus smartly. Here's a roadmap to maximize your learning:


Hour 1-2: Basics of Declarative Macros (macro_rules!)

βœ… Understand how macro_rules! works
βœ… Learn about patterns ($expr, $ident, $tt, $block)
βœ… Practice simple macros like println!, vec!, and custom ones

πŸ”Ή Exercises:
- Write a macro that squares a number
- Write a macro that repeats a string n times
- Write a macro that creates a HashMap

πŸ“š Reference:
- Rust Book - Macros


Hour 3-4: Intermediate Declarative Macros

βœ… Handle multiple arguments
βœ… Use recursion inside macros
βœ… Use tt (token trees) for flexible macros
βœ… Debugging macros (macro_rules! pitfalls)

πŸ”Ή Exercises:
- Write a min! macro that finds the smallest of multiple numbers
- Write a log! macro that prints with different log levels

πŸ“š Reference:
- Rust Reference - Macros


Hour 5-6: Introduction to Procedural Macros

βœ… Learn about proc_macro and proc_macro2 crates
βœ… Understand function-like, derive, and attribute macros
βœ… Write a simple derive macro (e.g., #[derive(Hello)])

πŸ”Ή Exercises:
- Create a custom derive macro that prints "Hello from struct!"
- Write a procedural macro that converts a function into an async version

πŸ“š Reference:
- Rust Book - Procedural Macros
- Rust API Docs - proc_macro


Hour 7-8: Advanced Procedural Macros

βœ… Work with syn and quote crates
βœ… Parse Rust syntax trees
βœ… Implement attribute-like macros (#[my_macro])

πŸ”Ή Exercises:
- Implement a macro that adds logging to any function
- Write a macro that converts function names to uppercase

πŸ“š Reference:
- Procedural Macros Workshop


Hour 9: Review, Experiment, and Write Your Own Macros

βœ… Revisit concepts
βœ… Implement your own creative macros
βœ… Debug and understand real-world macros (serde, tokio::main)


Tips for Staying Focused

πŸ’‘ Take short 5-minute breaks every hour
πŸ’‘ Code along with examples instead of just reading
πŸ’‘ Use cargo expand to see how macros expand


If you stick to this plan, you’ll get really comfortable with Rust macros. πŸ”₯ Want help with a specific macro concept while working through this?