Questions about importing packages

└── src
    ├── main.rs
    ├── test1.rs
    └── test2.rs

In main.rs:

mod test1;

fn main() {
    test2::foo();
}

In test1.rs:
pub mod test2;
In test2.rs:

pub fn foo() {
    println!("Hello.");
}

Then, I use rustc main.rs to compile. But it failed. What can I do to solve this?

Submodules must be placed in subfolders. If you want your module graph to look like main - test1 - tes2, you need to lay out files like this:

└── src
    ├── test1  <--- this is a folder
        └── test2.rs
    ├── main.rs
    └── test1.rs

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.