0
0
Rustprogramming~20 mins

Cargo dependency management in Rust - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Cargo Dependency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Cargo.toml dependency version resolution?

Given the following Cargo.toml snippet, what version of serde will Cargo use?

[dependencies]
serde = "^1.0.100"
serde_derive = "1.0.104"

Assume no other dependencies affect serde.

A1.0.100
B1.0.104
C1.0.99
D1.0.105
Attempts:
2 left
💡 Hint

Check how Cargo resolves compatible versions with caret requirements.

🧠 Conceptual
intermediate
1:00remaining
Which Cargo command updates dependencies to the latest compatible versions?

You want to update your Rust project's dependencies to the latest versions allowed by your Cargo.toml constraints. Which command should you run?

Acargo update
Bcargo refresh
Ccargo build --update
Dcargo upgrade
Attempts:
2 left
💡 Hint

Think about the official Cargo command that updates the lock file.

🔧 Debug
advanced
2:00remaining
Why does this Cargo build fail with a version conflict error?

Consider a Rust project with these dependencies in Cargo.toml:

[dependencies]
foo = "1.2.0"
bar = "2.0.0"

Both foo and bar depend on different incompatible versions of baz. What is the most likely cause of the build failure?

AThe <code>baz</code> crate is unpublished and cannot be downloaded.
BThe <code>Cargo.toml</code> file is missing a <code>[workspace]</code> section.
CCargo cannot unify incompatible versions of <code>baz</code> required by <code>foo</code> and <code>bar</code>.
DThe Rust compiler version is too old to build <code>foo</code> and <code>bar</code>.
Attempts:
2 left
💡 Hint

Think about how Cargo handles multiple versions of the same crate.

📝 Syntax
advanced
1:30remaining
Which Cargo.toml snippet correctly specifies a git dependency?

You want to depend on a crate from a Git repository instead of crates.io. Which snippet is correct?

A
[dependencies]
mycrate = { git = "https://github.com/user/mycrate.git", branch = "main" }
B
[dependencies]
mycrate = git: "https://github.com/user/mycrate.git", branch = "main"
C
[dependencies]
mycrate = { url = "https://github.com/user/mycrate.git", branch = "main" }
D
[dependencies]
mycrate = { git = "https://github.com/user/mycrate.git" branch = "main" }
Attempts:
2 left
💡 Hint

Check the correct key name and syntax for specifying git dependencies in Cargo.toml.

🚀 Application
expert
2:30remaining
How many dependencies will Cargo build with this workspace setup?

Given a Cargo workspace with two crates:

[workspace]
members = ["crate_a", "crate_b"]

# crate_a/Cargo.toml
[dependencies]
serde = "1.0"

# crate_b/Cargo.toml
[dependencies]
serde = "1.0"
regex = "1.5"

How many unique dependencies will Cargo compile for the entire workspace?

A1
B4
C3
D2
Attempts:
2 left
💡 Hint

Consider shared dependencies and unique dependencies across workspace members.