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
  • 326,504
  • 69
  • 892
  • 1,159
stuffy
  • 423
  • 5
  • 13

1 Answers1

4

Yes.

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

fn main() {
    print_ident!(foo);
}
DK.
  • 49,288
  • 3
  • 161
  • 146