首页 > 解决方案 > extern crate 语句之前的#[macro_use] 是什么意思?

问题描述

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

#[macro_use]
extern crate gotham_derive;

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

extern crate gotham_derive;

标签: rust

解决方案


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

Rust 1.30开始,通常不再需要这种语法,您可以改用标准use关键字。

查看The Rust Programming Language第一版中的宏章节以获取更多详细信息。


推荐阅读