Back to Rust Lang

Macros

redirects/macros.md

latest742 B
Original Source

% Macros

<small>There is a new edition of the book and this is an old link.</small>

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

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

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

Here are the relevant sections in the new and old books: