Rust logo
Rust 1.26.0
a77568041

Macros

There is a new edition of the book and this is an old link.

While functions and types abstract over code, macros abstract at a syntactic level.

macro_rules! five_times {
    ($x:expr) => (5 * $x);
}

fn main() {
    assert_eq!(25, five_times!(2 + 3));
}Run

This chapter does not exist yet in the second edition. You can check out other resources that describe macros.