I define a macro that generates code using a function defined in the same crate. I use the function's fully qualified name in order to be able to use it from any module:
mod a {
fn f() { println!("hi"); }
}
mod b {
#[macro_export]
macro_rules! m { () => { crate::a::f(); }}
}
mod c {
fn g() { crate::m!(); }
}
If I use that macro from another crate, I get a compiler error saying that there is no crate::a::f
. That makes sense as far as it goes, but I'd like to be able to write macros that are usable in both crates.
I could refactor the code so that the macros are defined in a crate by themselves, but is there a less invasive solution?
Is there a way to write a fully qualified name that is resolved correctly both from the same crate and from another crate?