Import a macro from a parent module

I'm having trouble reusing macros inside a box.

If the 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 do not see this macro in ./src/submod/lib.rs :

 my_macro!(...); 

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

Is there any way to import this macro into this submod child module?

+5
source share
1 answer

I get it! It is imported automatically, but I did not understand that macros are imported in order!

I imported the submod module to macros , so my_macro was not yet visible. By changing the order, I got the expected behavior.

+4
source

All Articles