Macros 无法导入/导出宏
我有一个名为Macros 无法导入/导出宏,macros,rust,Macros,Rust,我有一个名为macros.rs的模块,其中包含 /// Macro to easily implement FromError. /// from_error!(MyError, IoError, MyError::IoError) macro_rules! from_error { ( $t:ty, $err:ty, $name:path ) => { use std; impl std::error::FromError<$err>
macros.rs
的模块,其中包含
/// Macro to easily implement FromError.
/// from_error!(MyError, IoError, MyError::IoError)
macro_rules! from_error {
( $t:ty, $err:ty, $name:path ) => {
use std;
impl std::error::FromError<$err> for $t {
fn from_error(err: $err) -> $t {
$name(err)
}
}
}
}
当我尝试在项目的其他模块中使用
from\u error
时,编译器会说error:macro undefined:“from\u error!”代码>结果表明,声明模块的顺序很重要
mod json; // json uses macros from the "macros" module. can't find them.
#[macro_use]
mod macros;
#[macro_use]
mod macros;
mod json; // json uses macros from the "macros" module. everything's ok this way.
mod json; // json uses macros from the "macros" module. can't find them.
#[macro_use]
mod macros;
#[macro_use]
mod macros;
mod json; // json uses macros from the "macros" module. everything's ok this way.