Using $crate in Rust's procedural macros?

后端 未结 3 928
轻奢々
轻奢々 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:51

    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)

提交回复
热议问题