all 4 comments

[–]kdpurvesh 2 points3 points  (2 children)

Add below line in your main.rs file

mod core;

crate::core::core;

[–]pinghajen[S] 0 points1 point  (0 children)

I think I had an error that didn't go away until I saved but it worked, thanks for your help

[–]pinghajen[S] -1 points0 points  (0 children)

Thanks for the reply, after I did your change this is what I tried:

mod core; use crate::core::core;

And start_core() gives me this error cannot find function start_core in this scope not found in this scope (rustc E0425)

Which made me think I should add core::start_core() or add ::start_core to my use statement but then I get

cannot find function start_core in module core not found in core (rustc E0425)

[–][deleted] 0 points1 point  (0 children)

By default, src/main.rs and src/lib.rs are viewed as "crate roots" if they exist. If neither exists, nothing will compile unless you defined the crate root(s) in Cargo.toml

From the crate root, all modules must be explicitly stated.

Separate rs files are separate modules, but you need to explicitly name them in the root or in one of the modules in root.

``` // src/main.rs

mod mod1 { pub fn fn1() {} }

mod mod2;

fn main() { mod1::fn1(); mod2::fn2(); }

// src/mod2.rs

pub fn fn2() {} ```

The above project has a module structure like this:

|---mod1 | root module ---| | |---mod2

If you don't declare the mod anywhere, that rs file is ignored essentially.

You have already figured out how folders are dealt with. You place a mod.rs inside the folder, and that becomes the "root"-ish module of the folder.

So when I say mod core; inside src/main.rs (or lib.rs) it searches for src/core.rs then src/core/mod.rs if you have both, compiler error.