chshersh / tool-sync

🧰 Download pre-built binaries of all your favourite tools with a single command
https://crates.io/crates/tool-sync
Mozilla Public License 2.0
69 stars 16 forks source link

Refactoring module system #149

Closed MitchellBerend closed 1 year ago

MitchellBerend commented 1 year ago

Rust provides a couple of ways to organize projects. Currently there is a file in the root that imports all files in a dir with the same name. I propose we add a mod.rs file to the dir in question so it can be imported in src/lib directly. It would mean the same number of files but less noise in the root. The mod.rs is the equivalent of the python __init__.py.

With change image

Without change image

chshersh commented 1 year ago

I love less noise in the root directory 🙂 The current module structure is ad-hoc and evolved as the project grows. And I'm still navigating the best structure.

I mostly added those files due to unfamiliarity with the module system. But I'd happy to remove the model/mod.rs and similar modules if the code still works 🧹

I imagine it should be better for incremental compilation to import only relevant modules and not just reexporting ones (but I don't have enough Rust knowledge to confirm this).

Ideally, I'd love to keep only lib.rs and main.rs on the top level and move everything inside directories. And I still would like to have a separate directory with a module for executing each command, something like:

run/
    * sync.rs
    * install.rs
    * default-config.rs
    * completion.rs

Where lib.rs just calls run::sync(sync_args) or run::completion(completion_args)

chshersh commented 1 year ago

Also, some info I found on Rust module structure and best practices:

MitchellBerend commented 1 year ago
run/
    * sync.rs
    * install.rs
    * default-config.rs
    * completion.rs

I very much like this structure as well. I personally only make exceptions once there is a single file. The exception in this case would be the src/install.rs file.