Since, from rust 2018 mod.rs is no longer required, the file structure can be changed. Pls add your opinion.
{module}/mod.rs encapsulates the module hierarchically, keeping all of it on the same level (directory/folder/package/whatever). {module}.rs smears it across at least two levels. Doesn't matter if the file contains actual code or only re-exports.
Yeah my preference is to keep it as-is to keep it all at the same level.
My _real_ preference is to have implicit mod.rs and directly export public symbols from each file in a folder. But sadly rust chose to support every option _but_ my preference 馃槄
mod.rs is annoying. Spreading the module across two directories _without_ mod.rs is _also_ annoying. At least VS Code postfixes (and IntelliJ prefixes) file tabs with the parent directory when the file name is the same -- that helps somewhat in the mod.rs case. Not so long ago I remember just having a sea of bare mod.rs files. What a nightmare.
I'd love to see a {module}/{module}.rs option in Rust! Best of both worlds, IMO.
My real preference is to have implicit mod.rs and directly export public symbols from each file in a folder. But sadly rust chose to support every option but my preference
The following is similar (not implicit though) and is my favorite option for module organization of smaller crates. This is especially nice when a module_name.rs or module_name/mod.rs creates more file clutter than its worth only to export some items.
src/
- lib.rs
- foo/
- a.rs
- b.rs
- bar/
- c.rs
- d.rs
// lib.rs
// no need for foo.rs or foo/mod.rs
mod foo {
pub mod a;
pub mod b;
}
// keep the internal modules private
// and place all public items in bar
mod bar {
mod c;
pub use c::*;
mod d;
pub use d::*;
}
Whoa hold on that sort of changes everything. I didn't know we could do that :)
Closing this issue since there are many ways to organize files in Rust. Feel free to add your way of organizing files that might be helpfult to others
Most helpful comment
The following is similar (not implicit though) and is my favorite option for module organization of smaller crates. This is especially nice when a
module_name.rsormodule_name/mod.rscreates more file clutter than its worth only to export some items.