Referring to your own crate from within a macro

So I have a macro that needs to create code referencing another module of the crate

macro_rules! thing {
    ($e:expre) => {crate::thingy::doer()}

From inside the crate this works, but from outside it doesn't I need it to work both inside and out.

Any tips. Thanks

1 Like

Use $crate:

The keyword metavariable $crate can be used to refer to the current crate

via Macros By Example - The Rust Reference

1 Like

brill thanks

For the sake of completeness, for people stumbling upon this when writing a procedural macro, let's also have a pointer to Proc macros - using third party crate - #4 by Yandros

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.