rust - Unable to import/export macro -
i have module named macros.rs contains
/// macro 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> $t { fn from_error(err: $err) -> $t { $name(err) } } } } in main.rs import module this
#[macro_use] mod macros; when try use from_error in other modules of project, compiler says error: macro undefined: 'from_error!'.
turns out order in declare modules matters.
mod json; // json uses macros "macros" module. can't find them. #[macro_use] mod macros; #[macro_use] mod macros; mod json; // json uses macros "macros" module. everything's ok way.
Comments
Post a Comment