One of the issues with module/mod.rs
is that it leads to some confusion when trying to navigate and modify the module hierarchy.
With the module.rs
approach, you can reliably say that the way to find a::b::c
is to replace the ::
with /
and append .rs
: a/b/c.rs
. And you can always add a submodule by making a new directory, without having to git mv a/b/c.rs a/b/c/mod.rs
.
In the absence of mod.rs
, it's easier to know that whenever you descend a level in the module hierarchy, you descend a directory. You don't have these sideways moves from mod.rs
to submodulename.rs
, or unexpected downwards moves to submodulename/mod.rs
.
There's an exception to that: main.rs
and lib.rs
still act in many ways like mod.rs
, and that can be a source of confusion when projects grow past a single file and begin to modularize. It also causes some confusion in tests.
This isn't an issue when using things like src/bin/abc.rs
to define an abc
binary, because submodules of that are src/bin/abc/xyz.rs
.
Personally, I'm tempted to take that model further: if we moved bin
and lib.rs
up a level, we could have:
Cargo.toml
bin/name.rs
bin/name/submod.rs
lib.rs
lib/a.rs
lib/a/x.rs
lib/b.rs
lib/b/y.rs