The workflow is pretty simple as a project is defined in Rust with only a few files.
When your project has a src/lib.rs
file, then it's a library and can be called by other crates.
When your project has a src/main.rs
file, then it's built into an executable.
And your project can have both, which simplifies exposing functions of your application for other crates.
Here's a small example: rhit, which has both files.
As simple organization :
- declare all modules and
pub use
in the lib.rs
- have a
main
function in your main.rs, running the application
When your core features are more important and may be used in another application, or when the application needs dependencies which are useless for other applications needing your core features, then the alternative should be considered: separate your application in two crates witch clearly distinct roles. You may find this for example in lfs wich uses lfs-core, the latter one being available in other applications which won't import the specific dependencies of lfs.