Cargo.lock records the resolved versions of direct and indirect package dependencies, plus checksums used to verify their integrity. Cargo.toml declares dependency requirements; the lock file records the packages selected under those requirements. section 2.2.1 section 2.2
Choose version-control treatment by project type:
- Applications: commit Cargo.lock alongside Cargo.toml to help keep published releases consistent if third-party libraries change. section 2.2.1
- Libraries: leave Cargo.lock out of version control so downstream packages can update indirect dependencies as needed; with Git, add it to .gitignore. section 2.2.1
Run cargo update to refresh Cargo.lock to the newest available crates permitted by the dependency specifications. This differs from pinning a version with an exact requirement in Cargo.toml: the requirement controls which versions are eligible. section 2.2
Listing 2.1 A minimal Cargo.toml
[package] name = "simple-project" version = "0.1.0" authors = ["Brenden Matthews <brenden@brndn.io>"] edition = "2018" [dependencies] rand = "0.8"
The rand = "0.8" entry is a Cargo.toml dependency requirement, not a record of every resolved package version. section 2.2
Workspace members share one top-level Cargo.lock and its resolved dependency tree. Keep member dependencies declared in Cargo.toml; workspace membership does not replace dependency declarations. section 2.10
