Macro show_notes::print_ident_name [] [src]

macro_rules! print_ident_name {
    ($id:ident) => { ... };
}

Define an ident macro to show how they can capture different syntax.

Whereas main_try! captured expressions, print_ident_name! captures identifiers. If you try to pass in an expression, it simply won't work. So, if you tried to do any of these, it won't compile:

print_ident_name!(());
print_ident_name!(42);
print_ident_name!(if true { println!("Neato!"); } else { println!("Sads!"); });

Instead, it will complain that it expected an identifier, and you handed it something else.

On the other hand, this works just fine:

let _x = 0;
print_ident_name!(_x);  // "The ident's name was: _x"

In this case, the implementation uses two other macros: format! and stringify!, to accomplish its work. This highlights the reality that macros can use any other language machinery, including other macros.