I have a standard I've been using for organizing my personal projects. It's something I cobbled together from some standard advice and some tricks I worked out. I've found it very useful, but I'm starting to contribute to an open source project as the main Rust person, and I want to run this by more experienced people before I inflict it on the world.
I wrote out an example project at GitHub - edwardpeters/organizing_rust: A system for organizing modules that I've had success with to show it off in use.
The core idea is to organize imports without a lengthy and frequently changing
use block at the head of each module. I do this thru the use of a number of modules that are just containers for re-exporting. So, at the root of the crate are two modules:
pub(crate) mod crate_universal, which re-exports stuff that (for the most part) every individual .rs file should see
pub(crate) mod interface, which re-exports stuff that other crates should see on a flattened top level.
Then each mid-level module (nested however deep) has
pub(crate) mod crate_universal, which re-exports stuff from this module that you would want any other module in the crate to see (this is used by the top-level
pub mod interface, which similarly provides stuff from this module that should be on the interface for the entire crate
mod mod_universal, which re-exports things that should be seen by all the leaf modules of this crate
And finally each leaf module has
use super::mod_universal::*. (If a leaf has a lot, it can have its own re-export crates to describe what its parent should include in each of the three categories.)
The idea is that each mid-level module reports up the hierarchy the things that should be on the interface or seen by all implementation files; each mid-level module also passes down the hierarchy anything from that or other modules that should be used across that module.
For example, in this example I want
common_parts::Paint to be seen across the entire crate; by re-exporting these from
The goal of this is to offer a combination of flexibility and lightweight standardization. I find that almost every module I write only needs the
mod_universal exports from its parent module. Each mid-level module has a lot of flexibility in what it wants its children modules to see, or which of its contents are important enough to other crates to be re-exported into their standard namespace.
Finally, I included a few tests to show how I'm organizing those (I didn't do anything as weird there, I think I used standard practice?), and a couple of macros I use to set up the "standard" prefix at the head of each module.