0
0
Rustprogramming~5 mins

Cargo dependency management in Rust - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is Cargo in Rust?
Cargo is Rust's package manager and build system. It helps manage dependencies, compile code, and build packages.
Click to reveal answer
beginner
How do you add a new dependency to a Rust project using Cargo?
You add the dependency under the [dependencies] section in the Cargo.toml file with the package name and version.
Click to reveal answer
intermediate
What command updates all dependencies to the latest allowed versions in Cargo?
The command is cargo update. It updates the Cargo.lock file with the newest versions allowed by Cargo.toml.
Click to reveal answer
intermediate
What is the purpose of the Cargo.lock file?
Cargo.lock records the exact versions of dependencies used to ensure reproducible builds across different machines.
Click to reveal answer
advanced
How can you specify a dependency from a Git repository in Cargo.toml?
You specify the dependency with a git key and the repository URL, for example:<br>mycrate = { git = "https://github.com/owner/repo.git" }
Click to reveal answer
Where do you declare dependencies for a Rust project?
AIn the Cargo.lock file
BIn the main.rs file
CIn the Cargo.toml file
DIn the src folder
What does the command cargo build do?
AUpdates Cargo.toml
BOnly downloads dependencies
CRemoves unused dependencies
DCompiles the project and downloads dependencies if needed
What file ensures that all developers use the same dependency versions?
ACargo.lock
BCargo.toml
Cmain.rs
DREADME.md
How do you specify a dependency version range in Cargo.toml?
A"^1.2.3" means compatible with 1.2.3
B"=1.2.3" means any version
C"~1.2.3" means older than 1.2.3
D"*" means no dependencies
Which command updates the Cargo.lock file to the latest allowed dependency versions?
Acargo run
Bcargo update
Ccargo clean
Dcargo new
Explain how Cargo manages dependencies in a Rust project.
Think about where dependencies are listed and how Cargo ensures consistent builds.
You got /5 concepts.
    Describe how to add a dependency from a Git repository using Cargo.
    Focus on the syntax inside Cargo.toml for git dependencies.
    You got /4 concepts.