Question: I am working on a certain problem where given a URL I need to map it to a country. Even if I can reliably answer the question "Is this particular URL relevant to United States?" that should be sufficient. 

I am happy to have false negatives but never a false positive. 

Currently I am considering the following approach.

* See if the domain name of the URL is in top 1000 .com domains on Alexa for USA.
* Check if the the link was shared by US users on Facebook or twitter.

Has anyone solved this kind of problem before ?

Answer: 
Adding `#![macro_use]` to the top of your file containing macros will cause all macros to be pulled into main.rs.

For example, let's assume this file is called node.rs:

```
#![macro_use]

macro_rules! test {
    () => { println!("Nuts"); }
}

macro_rules! best {
    () => { println!("Run"); }
}

pub fn fun_times() {
    println!("Is it really?");
}

```

Your main.rs would look sometime like the following:

```
mod node;  //We're using node.rs
mod toad;  //Also using toad.rs

fn main() {
    test!();
    best!();
    toad::a_thing();
}

```

Finally let's say you have a file called toad.rs that also requires these macros:

```
use node; //Notice this is 'use' not 'mod'

pub fn a_thing() {
  test!();

  node::fun_times();
}

```

Notice that once files are pulled into main.rs with `mod`, the rest of your files have access to them through the `use` keyword.
I have [came across the same problem](https://stackoverflow.com/questions/63233545/how-do-i-use-rust-macros-in-the-same-crate) in Rust 1.44.1, and this solution works for later versions (known working for Rust 1.7).

Say you have a new project as:

```
src/
    main.rs
    memory.rs
    chunk.rs

```

In **main.rs**, you need to annotate that you are importing macros from the source, otherwise, it will not do for you.

```rust
#[macro_use]
mod memory;
mod chunk;

fn main() {
    println!("Hello, world!");
}

```

So in **memory.rs** you can define the macros, and you don't need annotations:

```rust
macro_rules! grow_capacity {
    ( $x:expr ) => {
        {
            if $x < 8 { 8 } else { $x * 2 }
        }
    };
}

```

Finally you can use it in **chunk.rs**, and you don't need to include the macro here, because it's done in main.rs:

```rust
grow_capacity!(8);

```

The [upvoted answer](https://stackoverflow.com/a/31749071/3340588) caused confusion for me, with [this doc by example](https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute), it would be helpful too.

---

**Note:** This solution does work, but do note as @ineiti highlighted in the comments, **the order u declare the `mod`s in the `main.rs/lib.rs` matters**, all `mod`s declared after the macros mod declaration try to invoke the macro will fail.