I know what the $crate variable is, but as far as I can tell, it can\'t be used inside procedural macros. Is there another way to achieve a similar effect?
I have an ex
In Edition 2015 (classic Rust), you can do this (but it's hacky):
::defining_crate::SomeTrait
in the macrodefining_crate
, the above works finewithin defining_crate
itself, add a module in the root:
mod defining_crate { pub use super::*; }
In Edition 2018 even more hacky solutions are required (see this issue), though #55275 may give us a simple workaround.
Based on replies from https://github.com/rust-lang/rust/issues/38356#issuecomment-412920528, it looks like there is no way to do this (as of 2018-08), neither to refer to the proc-macro crate nor to refer to any other crate unambiguously.
Since Rust 1.34, you can use extern my_crate as self
, and use my_crate::Foo
instead of $crate::Foo
.
https://github.com/rust-lang/rust/issues/54647
https://github.com/rust-lang/rust/pull/57407
(Credit: Neptunepink ##rust irc.freenode.net)