Invoke macro by reference/name

I can put a function in a variable, and call/invoke it by calling that variable with () as:

fn read(){}

main() {
   let f1: fn() = read;
   if true { f1() } else { println!("Sorry"); }

Can I do the same with macros! something like this:

macro_rules! hi{
    ($name:expr) => {
        format!("Hi {}", $name);

main() {
   let m1: ??? = hi;
   if true { m1!() } else { println!("Sorry"); }

No, you can't. Macros are expanded well before anything else is done (like name resolution), so this isn't possible in Rust.

Thanks a lot.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.