Repetición - Rust By Example
Description: Rust by Example (RBE) is a collection of runnable examples that illustrate various Rust concepts and standard libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Repetición

Macros can use `+` in the argument list to indicate that an argument may repeat at least once, or `*`, to indicate that the argument may repeat zero or more times.

In the following example, surrounding the matcher with `$(...),+` will match one or more expression, separated by commas. Also note that the semicolon is optional on the last case.

    // `find_min!` will calculate the minimum of any number of arguments.
    macro_rules! find_min {
        // Base case:
        ($x:expr) => ($x);
        // `$x` followed by at least one `$y,`
        ($x:expr, $($y:expr),+) => (
            // Call `find_min!` on the tail `$y`
            std::cmp::min($x, find_min!($($y),+))
        )
    }

    fn main() {
        println!("{}", find_min!(1));
        println!("{}", find_min!(1 + 2, 2));
        println!("{}", find_min!(5, 2 * 3, 4));
    }