2

This snippet prints $i, but I would like it to print foo. I've tried a few variations on this theme which didn't work, nor was I able to find anything in the documentation about this behavior. Is there syntax to make this possible?

macro_rules! print_ident {
    ($i:ident) => {
        println!("$i");  
    };
}

fn main() {
    print_ident!(foo);
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
skelley
  • 475
  • 5
  • 15

1 Answers1

4

Yes.

macro_rules! print_ident {
    ($i:ident) => {
        println!(stringify!($i));  
    };
}

fn main() {
    print_ident!(foo);
}
DK.
  • 55,277
  • 5
  • 189
  • 162