Cargo's 0.0.x and 0.x: the patch is the boundary
In one line: Why a bare version in Cargo means caret, why ^0.0.3 accepts only 0.0.3, and how commas and the missing || work.
Cargo version requirements look like npm's but differ in three ways: an omitted operator means caret, commas are AND, and there is no ||. Knowing those three answers most "why did it not resolve" questions.
Omitted means caret
[dependencies] serde = "1.0" # ^1.0 → >=1.0.0 <2.0.0 widget = "0.2.3" # ^0.2.3 → >=0.2.3 <0.3.0 tiny = "0.0.3" # ^0.0.3 → >=0.0.3 <0.0.4
In npm "0.2.3" means exactly 0.2.3. In Cargo it means ^0.2.3. This is the first thing people hit when porting manifests.
The two 0.x levels
| Requirement | Expanded | Meaning |
|---|---|---|
^0.2.3 | >=0.2.3 <0.3.0 | minor is the compatible unit |
^0.2 | >=0.2.0 <0.3.0 | same |
^0 | >=0.0.0 <1.0.0 | all 0.x |
^0.0.3 | >=0.0.3 <0.0.4 | patch is the compatible unit |
^0.0 | >=0.0.0 <0.1.0 | all 0.0.x |
~1.2.3 | >=1.2.3 <1.3.0 | minor fixed, patch free |
1.2.* | >=1.2.0 <1.3.0 | wildcards must stand alone |
^0.0.3 declares that 0.0.4 is not compatible. Crates that stay in 0.0.x often do change APIs every patch, so the conservative rule prevents surprises.
Comparison operators and partial versions
Cargo comparators keep partial versions. >1.2 means "greater than every 1.2.x", effectively >=1.3.0, while <1.2 means "less than every 1.2.x", effectively <1.2.0. npm reaches the same results by expanding >1.2 to >=1.3.0 and <=1.2 to <1.3.0-0.
Several conditions use commas
# at least 1.2.3 but below 1.5.0 widget = ">=1.2.3, <1.5.0"
Commas are AND. There is no OR in a manifest, so an alternative requirement has to become separate dependencies or feature flags. Cargo mode here reports || as a syntax error.
Prereleases
Cargo applies the same isolation rule as npm: a prerelease passes only when some comparator names the same major.minor.patch with a prerelease. ^1.0.0 does not accept 1.1.0-beta; ^1.0.0-beta.1 accepts 1.0.0-beta.2; * accepts no prerelease at all.
Exact pins
Write =0.0.3. In Cargo = with a full version means exactly that version, while =0.0 still means all 0.0.x. Applications with a committed Cargo.lock build reproducibly even with wide requirements, but for a library the requirement is the promise you make to users.
Paste the same constraints and candidate versions into this page to see which versions survive.
Open SemVerLabFrequently asked questions
Does 1.2 mean exactly 1.2.0 in Cargo?
No. An omitted operator is caret, so 1.2 equals ^1.2: >=1.2.0 <2.0.0.
Is 0.0.0 special?
^0.0.0 accepts only 0.0.0, because even a patch difference is treated as incompatible in 0.0.x.
Can a Cargo requirement use ||?
No. Only commas (AND); use separate dependencies or features for alternatives.
Sources
Read next
- The npm
^0.xtrap: why 0.3.0 falls outsideWhy^0.2.3ends at<0.3.0-0, how node-semver builds that bound, and which range to use for 0.x dependencies. - PEP 440
~=with post and dev: three rules in one operatorHow~=1.4.2computes its upper bound, how dev/pre/post order, and what epochs, local versions and.*do. - Prerelease ordering and isolation:
beta.11beatsbeta.2SemVer 2.0.0 §11 precedence, and how npm and Cargo keep prereleases out of ranges unless you ask for them.