Fully qualified name for use in macro

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_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?

I believe you can say $crate to refer to the crate that defines the macro.


thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.