A dependency is an external software package that a project needs. In Rust, Cargo records dependencies in Cargo.toml, downloads and compiles them, and manages build artifacts such as Cargo.lock and target/. section 1.3.1 section 2.11
A dependency connects several project activities:
- Declare the package and its version in Cargo.toml. section 1.3.1 section 2.11
- Ask Cargo to download and compile the package and its own required packages. section 1.3.1 section 2.11
- Use the resulting library from project code; Rust calls these packages crates. section 2.11
Adding a regular-expression dependency
Create a project with cargo new grep-lite --vcs none, enter its directory, and run cargo add regex@1. Cargo changes Cargo.toml to include regex, then cargo build downloads regex and supporting crates, compiles them, and builds grep-lite. The project can then grow from exact matching to regular-expression searches. section 2.11
Updating crates.io index Downloaded regex v1.3.6 Compiling lazy_static v1.4.0 Compiling regex-syntax v0.6.17 Compiling thread_local v1.0.1 Compiling aho-corasick v0.7.10 Compiling regex v1.3.6 Compiling grep-lite v0.1.0 (/tmp/grep-lite) Finished dev [unoptimized + debuginfo] target(s) in 4.47s
The build output makes dependency resolution visible: Cargo updates the crates.io index, downloads regex, compiles its supporting crates, and finishes the project build. section 2.11


























