Dependency management supplies Rust projects with libraries and applications through Cargo and the crates.io registry. Rust keeps many features outside the core language, so crates provide capabilities such as random-number generation. section 1.2.2 section 2.2
Use the dependency workflow to:
- Declare crates in Cargo.toml under [dependencies]. section 2.2
- Specify compatible versions with semantic versioning, including caret, tilde, wildcard, and comparison requirements. section 2.2
- Add a dependency from the command line with cargo add. section 2.2
Adding rand
A minimal Cargo.toml declares rand = "0.8". This selects the latest 0.8 release under Cargo's default caret requirement behavior; use explicit SemVer operators when a narrower or exact range is needed. 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"
Inspect the complete Cargo.toml listing, including package metadata, the 2018 edition, and the rand dependency. section 2.2
Table 2.2 Summary of SemVer dependency specification (view table figure)
Compare SemVer operators by minimum version, maximum version, and whether updates remain allowed. section 2.2




