I'm defining a macro that defines other macros like this:
macros.rs
#[macro_export]
macro_rules! m1 {
() => {
#[macro_export]
macro_rules! m2 {
() => {}
}
}
}
m1!();
m2!(); // no problem;
I can use m2!
in another crate by use {{crate_name}}::macros::*
, and I can use m2!
in macros.rs
, but I don't know how to use m2!
in files that are in the same crate.
lib.rs
#[macro_use]
pub mod macros;
pub mod test;
pub mod test2;
test.rs (in the same crate as macros.rs)
use crate::m1; // no problem
use crate::m2; // ERROR: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths
m1!(); // no problem
m2!(); // error, no m2
test2.rs
use crate::*;
m2!(); // this works, but I don't really want to use crate::*
examples/yo.rs
use {{crate_name}}::m2;
m2!(); // no problem
What is the correct way to use that m2
macro in other files in the same crate? I'm using Rust 1.31.1.