0

Welcome, this question is for sure repeated, but for past 2 hours my mod didn't work and im sure I've done everything correctly. Here is my tree:

project \
        |- target...
        |        
        |- rust_stuff...
        |
        \- src 
            |- main.rs
            |
            |- first_file.rs
            |            
            \- second_file.rs

And here is second one, for reference when i will list what i tried:

project \
        |- target...
        |        
        |- rust_stuff...
        |
        \- src 
            |- main.rs
            |
            |- first_file.rs
            |            
            \- cool_folder         
                   |
                   \second_file.rs

Ok, so we have:

// -- MAIN --
mod first_file;
pub use first_file::*;

fn main() {
   call_first();
}

Now, first_file.rs contains

// -- FIRST_FILE --
mod second_file; //E: Not found
pub use second_file; //E: Not used

pub fn call_first(){
   call_second(); //E: Out of scope
}

I will stop here, second_file exists, and cannot be accesed by first_file but can be accessed by main just like this:

// -- MAIN --
mod first_file;
pub use first_file::*;

mod second_file;
pub use second_file::*;

fn main() {
   call_first(); //Would call 'call_second' but as i presented it can't
   call_second(); //Returns "Hello world" in terminal
}

(Thats assuming second_file is same as first_file with just different function naming)
Now, reffering to second tree i showed, i tried putting those files in cool_file, but it worked out the same except i used:

mod cool_file; //Err

pub use cool_file::*;
// this does not work

pub use second_file::*;
// neither does this

In documentation from what i understand, i wrote it the right way, in regards to first example, i have no idea what to do. Please help.

Armado
  • 5
  • 1
  • 6
  • `mod` is meant to be put in main or `lib.rs`. From other modules you can write `use crate::second_file` – Ibraheem Ahmed Feb 04 '21 at 20:06
  • 1
    If you do want `second_file.rs` to be nested within `first_file.rs`, then rename `cool_folder` to `first_file` and then `mod second_file;` in `first_file.rs` will work. – kmdreko Feb 04 '21 at 20:12

0 Answers0