liveBook · Manning

Crates.io

As explained in Code Like a Pro in Rust

crates.io is the public package registry for Rust libraries and applications.

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

How Code Like a Pro in Rust covers it

How deep it goes
Defines the registry and demonstrates Cargo.toml declarations and SemVer ranges, while deferring broader Rust tooling.
Examples
Uses rand, cargo add rand, a minimal Cargo.toml, and a SemVer requirements table.
What it assumes
Assumes Rust and Cargo familiarity while introducing crates as Rust’s primary extension mechanism.
What you can do after
Apply Cargo dependency management by declaring crates and selecting compatible version requirements.
How it connects
Connects crates.io with Cargo, Cargo.toml, semantic versioning, and the rand crate.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.