Importing Issue

I am struggling about importing a file in rust.

There is no error in the following situation.

In a.rs

// There is no import

In b.rs

mod c;

In c.rs

pub struct Number{}

But there is an error in file b.rs when I am tring to write "mod b.rs;" to file a.rs.
Why is this happening? What is the reason of this problem? And how can I fix this?

I'm not sure exactly what your issue is, but here's a tip: before you start to break things up into files, first figure out how you want to define modules. Maybe you want something like this?

// main.rs or lib.rs
mod a {
    /* ??? */
}

mod b {
    mod c {
        pub struct Number {}
    }
}

Start with all code in the same file and modules defined in-line. Get it working that way first, and only then start breaking out modules into their own files.

1 Like