macros

Declarative macros (macro_rules!) for code generation

Declarative macros (macro_rules!) let you write code that writes code, reducing boilerplate. They pattern-match on token trees and expand at compile time. I use them for repetitive patterns like implementing traits for multiple types or generating tes

Laravel macro methods for extending framework

Macros dynamically add methods to Laravel's macroable classes—Request, Response, Collection, Query Builder, and more. I define macros in service providers' boot() methods. The macro() method accepts a name and closure. Macros access $this context like

Derive macros for automatic trait implementations

Rust's #[derive] attribute auto-generates trait implementations for common traits like Debug, Clone, PartialEq, and Serialize. This eliminates boilerplate and ensures consistency. For example, #[derive(Debug)] generates a debug formatter that prints a

cargo-expand to inspect macro expansions

cargo expand is a subcommand that shows the output of macro expansion. It's invaluable for debugging derive macros, understanding what declarative macros produce, or learning how async functions desugar. I run cargo expand --lib to see the entire crat

Procedural macros for custom derives and attributes

Procedural macros operate on Rust syntax trees, enabling custom #[derive(...)], attribute macros, or function-like macros. I write proc macros for boilerplate reduction: auto-generating builders, serialization, or validation. They're more powerful tha