November 2017
Intermediate to advanced
264 pages
5h 45m
English
The basic structure of a macro definition for a macro with the name mac1 is of this form:
macro_rules! mac1 {
(pattern) => (expansion);
(pattern) => (expansion);
...
}
So, we can see that the definition of a macro is also done through a macro, namely the macro macro_rules! ;As you can see, a macro is similar to a match block, defining one or more rules for pattern matching, each rule ending on a semicolon. Every rule consists of a pattern before the => sign (also called a matcher) that is replaced with the expansion part during compilation, not while executing the code.
The macro can be called as either mac1!() or mac1![]; the braces contain the arguments.
The following macro, welcome! , expects no pattern and expands into ...
Read now
Unlock full access