How do I use a macro across module files?
@lebyy▲ 0 net votes
Problem: I have two modules in separate files within the same crate, where the crate has macro_rules enabled. I want to use the macros defined in one module in another module. // macros.rs #[macro_export] // or not? is ineffectual for this, afaik macro_rules!… Fix (from the top answer): Macros within the same crate New method (since Rust 1.32, 2019-01-17) foo::bar!(); // works mod foo { macro_rules! bar { () => () } pub(crate) use bar; // <-- the trick } foo::bar!(); With the pub use , the macro can be used and imported like any other item. And unlike the older method, this does not rely on source…