Macros defined in submodules?


Hi there,

I cannot seem to get macros defined in submodules to work.

Here is my app structure:


I tried all the possible combinations of #[macro_use], but never gets visibility on my macro.

use app::util::macros;


pub mod util;


pub mod traits;
pub mod macros;


macro_rules! hashmap {
    ($( $key: expr => $val: expr ),*) => {{
         let mut map = ::std::collections::HashMap::new();
         $( map.insert($key, $val); )*

What did I do wrong? (I read the doc, and also multiple SO threads, still no luck)

Thank you in advance

Best regards,


In you never actually tell rustc that the app directory exists.

If you replace with the following you will be able to use the macro.

mod app;

Remember, #[macro_use] can only be used with mod or extern crate, not use.

For example, if you want to use macros from a seperate crate, you could write

extern crate regex;

Here is a more complete guide on macros:


Hi neon,

Sorry, I did not write all my code, but I actually did do mod app; before useing the submodules.

However, it was indeed the only place where I did not put #[macro_use] (must be the exhaustion, because I have been at it for almost 1h and it’s very late here)

I changed that, and it works!! Well, except for an another unrelated error, but that I could fix without too much hassle.

Thank you for your help Neon! With all the Rustaceans kind help, I believe I may be able to understand the basics of Rust enough to successfully use Rust as the webserver for our application! And I’m all excited about this idea! :smile: (even though some people tend to discourage it, but whatever, I like Rust spirit)

Best regards,


Glad to be of assistance. I was just clicking around the forums trying to get help with my own issue and I spotted this and thought it should be solvable.


Well, good luck with your issues then (I’m afraid I won’t be of much help), but thanks again for the help, I was already in bed and jumped out of it to test your solution, and I’m glad I did :slight_smile: Thanks!