Need clarity for files modules and crates

I have a situation where in one project (using VSCode) I have 3 files; a(has main()), b, and c.

In access file b from file a using:

mod b;
use b::B;

In file b, I access file c by using:

use crate::c::C;

and all is well, but in another project, I do the same thing and get the error within file b:

1 | use crate::c::C;
  |            ^^^^^^^^^^ maybe a missing crate `c`?

What's going on here?
(When I place all the code from file c in file b the app works)

The compiler only looks for modules that match a mod statement in your code. Your root file (a in this case) needs to have a mod c; declaration for the file to get read in, and then it should be accessible as crate::c.

1 Like

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.