The best way to break up codes is by functional units. Each module should export a few symbols but lots of cross-coupling is a bad sign.
If you have a lot of complex structs, it can be useful to make multiple sub-modules for each struct. This is also applicable to other implementations such as enums. All implementations for these structs should be in their module. The module root can then re-export them in a flat way.
Cross-coupling between modules and especially between levels is a ‘Code Smell’ or a symptom of bad design. You should use visibility modifiers to control access to implementations only where they are needed.
For many architectures testing within each module is sufficient for unit testing. However, if necessary, depending on an organization, tests can be placed in a sub-module, generally in the same file.
Watch the video to walk through each of the methods in detail. If you liked the video, don’t forget to check out the comprehensive course Learning Rust, packed with step-by-step instructions, working examples, and helpful tips and techniques on working with Rust.
Leo Tindall is a software developer and hacker from San Diego whose interests include scalability, parallel software, and machine learning.
9 reasons why Rust programmers love Rust
Rust as a Game Programming Language: Is it any good?
Rust 2018 RC1 now released with Raw identifiers, better path clarity, and other changes