Using $crate in Rust's procedural macros?

后端 未结 3 929
轻奢々
轻奢々 2021-02-05 08:21

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

3条回答
  •  孤独总比滥情好
    2021-02-05 08:38

    In Edition 2015 (classic Rust), you can do this (but it's hacky):

    • use ::defining_crate::SomeTrait in the macro
    • within third-party crates depending on defining_crate, the above works fine
    • within 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.

提交回复
热议问题