在 Rust 程序宏中使用 $crate?

2023-12-28

我知道什么是$crate https://doc.rust-lang.org/1.5.0/book/macros.html#the-variable-crate变量是,但据我所知,它不能在过程宏中使用。还有其他方法可以达到类似的效果吗?

我有一个例子,大致要求我使用以下内容编写类似的内容quote https://github.com/dtolnay/quote和夜间 Rust

quote!(
     struct Foo {
        bar: [SomeTrait;#len]
     }
)

我需要确定SomeTrait是在范围内(#len正在引用片段范围之外的整数)。

我在夜间使用程序宏 2.0 使用 quote 和 syn 因为proc-macro-hack不适合我。我试图概括一下。


从 Rust 1.34 开始,你可以使用extern crate self as my_crate,并使用my_crate::Foo代替$crate::Foo.

https://github.com/rust-lang/rust/issues/54647 https://github.com/rust-lang/rust/issues/54647

https://github.com/rust-lang/rust/pull/57407 https://github.com/rust-lang/rust/pull/57407

(来源:Neptunepink ##rust irc.freenode.net)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Rust 程序宏中使用 $crate? 的相关文章

随机推荐