Best Practices for Managing Shared Rust Code Across Multiple Projects

Hello Rust community,

I am working on a project where multiple Rust applications share some common functionality implemented in .rs files, such as redis.rs with several methods to download and upload, fs.rs for some file related methods, docker.rs some docker stuff. Currently, I have copied these files across different repositories, which is not ideal as it leads to maintenance issues and inconsistencies.

Can anyone suggest the best way to manage shared Rust code across multiple projects? I'm looking for a solution that allows me to maintain a single source of truth for these shared files, ensuring that updates propagate consistently across all projects that rely on them.

Some options I've considered include creating a shared library and using Git submodules

Thank you for your guidance!

You could make them into one or more shared crates (the structure depends a bit on what you need) and add them as path or git dependencies.

It gets a bit more complex if you intend to publish the crates on crates.io, since the shared crate(s) need to be published as well.

1 Like