I have a module named macros.rs
which contains
/// 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)
}
}
}
}
In my main.rs
I import the module like this
#[macro_use] mod macros;
When I try to use from_error
in other modules of my project, the compiler says error: macro undefined: 'from_error!'
.
Turns out that the order in which you declare modules matters.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With