Hello,
I've made it a habit to have my Rust projects include both a main.rs
and a lib.rs
. Most of the functionality would be attached to lib.rs
, while main.rs
mostly just exposes some of that functionality through a command line interface.
The main question: should Cargo.lock
be listed in .gitignore
?
The documentation says that Cargo.lock should be shared (i.e. committed to the repository, i.e. not listed in .gitignore
) if it is a binary crate (i.e. has main.rs
), but not if it is a library crate (i.e. has lib.rs
).
What if you have both? In that case, two crates will be created: one binary crate based on main.rs
and one library based on lib.rs
. Will Cargo.lock
affect the library crate? More precisely, if the library crate from project A will be used by project B, will Cargo.lock
from project A be taken into consideration when building project B?
I'm hoping the answer is no. In that case, I'd assume Cargo.lock
only affects the binary crate and should be shared (i.e. not listed in .gitignore
).
Either way, I'd suggest to update the documentation to clarify this.
Thanks!
Best, Oliver