rust - extern crate 语句前的#[macro_use] 是什么意思?

标签 rust rust-macros

在 Rust 中,我有时会在 extern crate 语句之前看到 #[macro_use]:

#[macro_use]
extern crate gotham_derive;

与没有 #[macro_use] 相比,这有什么作用?

extern crate gotham_derive;

最佳答案

这意味着从 crate 中导入(“使用”)宏。

截至Rust 1.30 ,通常不再需要此语法,您可以改用标准的 use 关键字。

查看 macros chapter from the first edition of The Rust Programming Language了解更多详情。

关于rust - extern crate 语句前的#[macro_use] 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54953571/

相关文章:

types - 有没有办法创建只接受一系列值的数据类型?

rust - 将非静态生命周期传递给 Rocket 的管理

rust - 如何使用 Cargo 下载 crate 的文档?

rust - 如何创建 proc_macro_attribute?

rust - 如何在递归 macro_rules 中扩展子模式?

rust - 是否可以忽略 Rust 的指数?

rust - Pin::as_mut(&mut self )

rust - 将 `Deref` 实现为返回复合结构的字段是惯用的吗?

rust 宏 : Calling function dependent on expression

rust - 写!引用时宏不会在单独的方法中编译