I just discovered that, while in main.rs
I can do:
use mylibs::math;
...when mylibs
is the name of a module directory. But, from every other file in my project, including another file right next to it in the same directory, say notmain.rs
, I must do:
use crate::mylibs::math;
This seems like an odd exception. I read through the docs, and the changes from Rust 2015 to 2018, which seems to confirm what I'm thinking.
I've never seen this explicitly said, though: main.rs
(and maybe lib.rs
) act differently from all other files in a package / crate. Is this correct? (If this is the case, I may just forgo the mylibs
"namespacing" because crate::
communicates the same concept: that this is local code. At least, it does this in non-main.rs
files. (!?)
It seems that, except for in main.rs
, these paths are interpreted as relative. (?)
EDIT: Another exception I think I found:
- A
mod
declaration is required inmain.rs
but not in other files.