Macros are not new to you as we have already used them. Every time we called an expression that ended with an exclamation mark (
!), we called a built-in macro; the
! sign distinguishes it from a function. In our code until now, we have already used
Macros make powerful language or syntax extensions; therefore, they make metaprogramming possible. For example, Rust has a
regex! macro that allows you to define regular expressions in your program, which are compiled while your code is compiled. This way the regular expressions are verified, they can be optimized at compile time, and there is no runtime overhead.
Macros can capture repetitive or resembling code patterns and replace ...