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.
Check how Cargo resolves compatible versions with caret requirements.
Caret requirements like ^1.0.100 allow versions >=1.0.100 and <2.0.0. Cargo picks the highest compatible version. Since serde_derive requires 1.0.104, Cargo uses 1.0.104 for both.
You want to update your Rust project's dependencies to the latest versions allowed by your Cargo.toml constraints. Which command should you run?
Think about the official Cargo command that updates the lock file.
cargo update updates the Cargo.lock file to the latest versions allowed by Cargo.toml. cargo upgrade is from an external tool, not built-in.
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?
Think about how Cargo handles multiple versions of the same crate.
Cargo tries to unify dependencies to a single version. If foo and bar require incompatible versions of baz, Cargo cannot resolve the conflict, causing a build failure.
You want to depend on a crate from a Git repository instead of crates.io. Which snippet is correct?
Check the correct key name and syntax for specifying git dependencies in Cargo.toml.
The correct syntax uses git as the key inside braces with commas separating fields. Option A is correct. Option A uses invalid syntax, C uses wrong key url, and A misses a comma.
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?
Consider shared dependencies and unique dependencies across workspace members.
Both crates depend on serde "1.0" (compatible, so compiled once). crate_b also depends on regex. Thus, two unique dependencies: serde and regex. Workspace members are packages, not dependencies.