Move independent modules to crates in same repository?

I've been building a binary application in rust, and looking over the modules that have been written, I realized there were more than a few that can operate independently from the rest of the program (they don't depend on any other modules in the application).

Would it be in my best interest to move these modules into sub-crates? This would just be crates in sub-directories of the repository, specified in the main application crate with path = "./.../". I was thinking of doing this just speed up compile times, so that independent parts which didn't change didn't have to be rebuilt.

Are there any specific advantages/disadvantages to doing this that one should be aware of?

A potential major disadvantage is not all code is eligible for cross-crate inlining. So if you're calling into these submodules in tight loops or relying on some "zero cost" abstraction to get stripped away, you might have trouble.

Any code marked #[inline] or using generics is eligible for cross-crate inlining, though (at the cost of bloating up your crate with the source).

1 Like