12

I'm having trouble re-using macros within a crate.

If a macro is defined in ./src/macros.rs:

#[macro_export]
macro_rules! my_macro {
    ...
}

and used in ./src/lib.rs:

#[macro_use]
pub mod macros;

I can't see this macro in ./src/submod/lib.rs:

my_macro!(...);

It yields the error message error: macro undefined: 'my_macro!'.

Is there a way I can import this macro in this child module submod?

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
marcusklaas
  • 492
  • 5
  • 15

1 Answers1

11

I figured it out! It is imported automatically, but I didn't realize that macros are imported in order!

I imported the submod module before macros, so my_macro wasn't visible yet. By swapping the order, I got the expected behaviour.

marcusklaas
  • 492
  • 5
  • 15