After reading this, I'm wondering why there is a mod keyword and mod.rs?
I assumed that the directory hierarchy can describe the module as well.
After reading this, I'm wondering why there is a mod keyword and mod.rs?
I assumed that the directory hierarchy can describe the module as well.
There are a couple of reasons why modules must be explicitly declared:
Modules can be public (pub mod foo;) or private (mod foo;).
They can have attributes applied to them, attributes that couldn’t sit inside the file; there are two primary examples of that: #[path = "x.rs"] specifying a different path, and #[cfg(…)], for conditional compilation, for cases where the module would fail to parse or have its macros expand.
While it can, it can also be overridden:
#[path = "somewhere/else"]
mod lol;