问题描述
我正在尝试 Rust Edition 2018 一个>.在Rust 2015中,您使用
I'm experimenting with Rust Edition 2018. In Rust 2015 you use
#[macro_use]
extern crate log;
用于导入宏.在Rust 2018中,extern crate
可能很简单.有没有一种方法可以在不使用extern crate
的情况下从板条箱中导入所有宏?对于简单的宏,将其导入模块很好,但是复杂的宏依赖于其他几个宏,这很不方便.
for importing macros. In Rust 2018 extern crate
is probably unidiomatic. Is there a way, to import all macros from the crate without extern crate
? For simple macros, importing it in the modules is fine, but complicated macros depend on several other macros, which is unhandy.
推荐答案
我看不到任何仅导入 宏的方法,但是如果可以导入所有基本对象, crate提供,通常应通过以下方式获取所有宏:
I don't see any way of importing only all the macros, but if you are fine with importing all the essential objects a crate provides, you should usually get all the macros by writing:
use the_crate_with_macros::*;
或
use the_crate_with_macros::prelude::*; // if available
从1.30版开始,这也适用于Rust 2015.
This also works in Rust 2015 starting in version 1.30.
这篇关于如何在Rust 2018中导入所有宏,派生和过程宏而不使用外部包装箱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!