Advice on Structuring a Rust Project for a Library and CLI

Hello Rust community,

I'm relatively new to Rust and planning to implement a library that compiles workflows, previously done in Python, to take advantage of Rust's performance features. I'm seeking advice on the project structure.

Initially, I considered having both the library and a CLI in the same repository. However, I now think it might be better to separate them into different repositories. The idea is to have the library as a standalone component, making it available for various use cases, such as a CLI and potentially a web API in the future. This way, if I want to utilize the library in different scenarios, I can simply add it as a dependency.

Is this approach valid? I would appreciate any feedback or recommendations on how to structure the project effectively for long-term flexibility and maintainability.

Thank you!

Note that you can have the library and CLI in the same repository but still support users installing only the library by making the repository into a workspace with two packages, one for the library and one for the CLI. Among other benefits, this makes it easier to test the two packages in lock-step.


Besides a workspace, you can even have both targets (also called crates) in the same package, without reducing your ability to use the library in other projects, or not being able to install the CLI with cargo install. Binary targets in your package get your library added as a dependency automatically by Cargo. I like this better than workspaces or splitting your project across multiple repositories, as this decreases manual labour required with keeping versions up to date.