Macro with optional parameter to say hello
- In this macro we have two "arms". The first will handle the case when no paramater is passed.
- We can have separate implementations or we can recursively use the macro.
examples/macros/say-hello-optional/src/main.rs
macro_rules! say_hello { () => { println!("Hello World!"); // alternatively we could re-use the macro: //say_hello!("World"); }; ($name: expr) => { println!("Hello {}!", $name); }; } fn main() { say_hello!("Foo"); say_hello!("Bar"); say_hello!("Foo Bar"); say_hello!(); }