Back to course

Macros: Code that Writes Code

Rust for Systems & Web3 Security

Metaprogramming in Rust

Macros (like println! or vec!) allow you to write code that generates other code.

  • Declarative Macros: macro_rules!.
  • Procedural Macros: Like #[derive(Serialize)].

In Web3, procedural macros are used to generate Smart Contract boilerplate (e.g., in the Anchor framework for Solana).