我正在尝试Rust Edition 2018。在Rust 2015中,您使用
#[macro_use]
extern crate log;
用于导入宏。在Rust 2018中,extern crate
可能很简单。有没有办法从板条箱中导入所有宏而不使用extern crate
?对于简单的宏,importing it in the modules很好,但是复杂的宏依赖于其他几个宏,这很不方便。
答案 0 :(得分:7)
我看不到任何仅导入 所有宏的方法,但是如果您可以导入板条箱提供的所有基本对象,则通常应通过以下方式获取所有宏:< / p>
use the_crate_with_macros::*;
或
use the_crate_with_macros::prelude::*; // if available
从1.30版开始,这也适用于Rust 2015。
答案 1 :(得分:4)
如前所述,您可以通过
导入单个宏use foo::mac1;
要一次导入多个宏,可以使用nested imports
use foo::{mac1, mac2, mac3};
或依靠板条箱创建者,他们将允许您通过单个glob导入它,例如
use foo::macros::*;