mod some_mod;
Simply means "there exists some file called some_mod.rs
in this directory, or there exists some directory called some_mod
in this directory that contains a file called mod.rs
. Typing this line will make whatever content contained within the file (some_mod/mod.rs
or some_mod.rs
) available in this file via some_mod::whatever
.
So Rust source files are modules. There is also a handy inline syntax for defining a short sub-module in the current file/module without needing to have a separate file for this module. This syntax is the source of confusion for a lot of people as it makes them think they have to write mod some_mod {
to define any modules. Nope, this is just an inline shortcut for making a separate file and putting stuff in there, like the following:
mod some_other_mod {
// stuff in here