Macro with parameter to say hello


// $t:ty means we have a paramerer called $t and it has a type "ty" (type, such as i32 or f64) // With this macro we can replace a short syntax with a longer syntax in at compile time.


examples/macros/say-hello/src/main.rs
macro_rules! say_hello {
    ($name: expr) => {
        println!("Hello {}!", $name);
    };
}

fn main() {
    say_hello!("Foo");
    say_hello!("Bar");
    say_hello!("Foo Bar");

    // say_hello!("Foo", "Bar");
    // ^ no rules expected this token in macro call

    // say_hello!();
    // ^^^^^^^^^^^^ missing tokens in macro arguments
}