
Understand it
"1.2" means any 1.x at or above 1.2, because Cargo follows SemVer: patch and minor releases must stay compatible. The resolver picks the highest match and records the exact choice in Cargo.lock, and features let one crate ship optional pieces you opt into rather than paying for by default.
A dependency declaration is a compatibility request, not a permanent pin. In Cargo's default caret requirement, version = "1.2" accepts compatible 1.x releases from 1.2 upward but not 2.0. Cargo.lock records the concrete versions selected for a particular resolution, so two developers can rebuild the same application graph. Read both files when investigating why a new release did or did not appear in your build.
Features let a dependency expose optional capabilities. In the example, serde with derive enables procedural derives; default-features = false on another dependency removes only that dependency edge's default request. Features are unified when the same package is reached through several paths, so another dependency can still turn a feature on. Treat features as additive options, and inspect the resolved feature graph when behavior surprises you.
Before adding a crate, check what problem it solves, whether its API fits the project, and what it brings into the build. A small dependency can be worthwhile, but every dependency adds a maintenance and security surface. Pinning every version forever is not a substitute for tests; compatible updates still need verification. Practice with cargo tree to inspect the graph, update one package deliberately, and run tests after the lockfile changes. Keep direct dependency declarations clear and leave transitive selection to the resolver unless a real constraint requires intervention.
When reading a version requirement, pay attention to pre-release versions and major version zero, whose compatibility rules are narrower. Do not infer safety solely from a SemVer range; examine release notes and run meaningful tests after updates.
Execution profile: the Serde: Decode, Validate, Encode lesson contains the qualified, pinned Cargo project for both the app and web Playground. It uses explicit Serde traits. Enabling derive adds a procedural macro dependency and needs separately qualified macro support; downloading serde alone does not provide that capability.
Read the code
[dependencies]
serde = "=1.0.229"
serde_json = "=1.0.151"
smallvec = "1"
memchr = { version = "2", default-features = false }A requirement, a feature set, and an opt-out of defaults.
Practice starter
[dependencies]
example = "0.4"Try it
Add a dependency with an explicit feature and resolve it.
What success looks like: Cargo.lock pins an exact version that satisfies the requirement.
Check your understanding
Which version can that requirement resolve to?
Reveal the answer
- 0.5.0
- 0.4.9
- 1.0.0
Below 1.0 the minor number is the breaking one, so 0.4.x only.
Go deeper
Common misconception: “"0.4" works like "1.2", so any newer 0.x release is allowed.”
Below 1.0 the minor number is the breaking one, so "0.4" means >=0.4.0 and <0.5.0. Cargo.lock then records the exact version chosen.
- Read the requirement:
smallvec = "1"accepts any compatible 1.x release, not one fixed version. - Read the features:
features = ["derive"]adds toserde's defaults, whiledefault-features = falsedrops the default request formemchron this edge. - Find the real choice: The resolver picks exact versions and writes them to
Cargo.lock;cargo treeshows the graph it selected.
Transfer challenge: Add log = "0.4" and write down the range it allows. Run cargo update -p log in a copy of the project and check that Cargo.lock stays inside that range.
Connections
- Error Design: Propagation and custom errors
- Workspaces: Many crates, one lockfile
Learn this lesson with AI
Paste this into Claude, Codex, Cursor or another agent connected to Crabrix Academy. It contains only this lesson’s public details.
I'm learning Rust with Crabrix Academy. Teach me this lesson with the Crabrix Academy tools. Lesson: Dependencies (courseId "projects", lessonId "dependencies") Link: https://crabrix.com/learn/projects/dependencies/ Goal: "1.2" means >=1.2.0 and <2.0.0; the lockfile records what was actually chosen. Practice: give me the lesson's exercise (crabrix_academy_get_exercise); I will write and run the code in Crabrix. Explain it step by step for my level, let me write the code myself, give hints before any solution, and do not mark anything as passed: only Crabrix checks do that.