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 m
This answer is outdated as of Rust 1.1.0-stable.
You need to add #![macro_escape]
at the top of macros.rs
and include it using mod macros;
as mentioned in the Macros Guide.
$ cat macros.rs
#![macro_escape]
#[macro_export]
macro_rules! my_macro {
() => { println!("hi"); }
}
$ cat something.rs
#![feature(macro_rules)]
mod macros;
fn main() {
my_macro!();
}
$ rustc something.rs
$ ./something
hi
For future reference,
$ rustc -v
rustc 0.13.0-dev (2790505c1 2014-11-03 14:17:26 +0000)