October 2019
Intermediate to advanced
444 pages
10h 37m
English
Code generation can be as easy as these few steps:
// Repeat the statement that was passed in n timesmacro_rules! n_times { // `()` indicates that the macro takes no argument. ($n: expr, $f: block) => { for _ in 0..$n { $f() } }}
// Declare a function in a macro!macro_rules! make_fn { ($i: ident, $body: block) => { fn $i () $body } }
Read now
Unlock full access