crates.io is Rust’s public package registry for crates, which include libraries and applications. Rust relies on crates to provide capabilities beyond its deliberately minimal core language and standard library. section 2.2
Use crates.io through Cargo to:
- Declare dependencies in Cargo.toml, such as rand = "0.8". section 2.2
- Add a dependency from the command line with cargo add rand. section 2.2
- Choose compatible versions with semantic-versioning requirements, including caret, tilde, wildcard, and comparison operators. section 2.2
A dependency in Cargo.toml
A minimal project can list rand under [dependencies] with version "0.8". Cargo then manages the third-party crate instead of requiring manually integrated build checks or vendored build systems. 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 minimal Cargo.toml listing showing package metadata and a crates.io dependency. section 2.2
