10aday › Version Constraint Checker › Cargo.toml version requirements
"1.2.3", ^, ~, * and = really allowShort answer: in Cargo.toml a bare version is a caret requirement:
serde = "1.2.3" allows ≥1.2.3 <2.0.0, and rand = "0.8.5" allows ≥0.8.5 <0.9.0. To pin one version, write "=1.2.3".
npm reads the same bare string as an exact version, which is why copying requirements between package.json and Cargo.toml changes their meaning.
Have a constraint and a list of versions? Paste them into the Version Constraint Checker: it shows, side by side, what npm, Cargo, Composer, pip and RubyGems accept.
Highlighted: npm reads the same string differently.
| Constraint | Cargo | npm | |
|---|---|---|---|
"1.2.3" (bare) | ≥1.2.3 <2.0.0 | exactly 1.2.3 | try it |
"1.2" (bare) | ≥1.2.0 <2.0.0 | ≥1.2.0 <1.3.0 | try it |
"1" (bare) | ≥1.0.0 <2.0.0 | ≥1.0.0 <2.0.0 | try it |
"0.2.3" (bare) | ≥0.2.3 <0.3.0 | exactly 0.2.3 | try it |
"0.0.3" (bare) | ≥0.0.3 <0.0.4 | exactly 0.0.3 | try it |
^1.2.3 | ≥1.2.3 <2.0.0 | ≥1.2.3 <2.0.0 | try it |
^0.2.3 | ≥0.2.3 <0.3.0 | ≥0.2.3 <0.3.0 | try it |
~1.2.3 | ≥1.2.3 <1.3.0 | ≥1.2.3 <1.3.0 | try it |
~1.2 | ≥1.2.0 <1.3.0 | ≥1.2.0 <1.3.0 | try it |
~1 | ≥1.0.0 <2.0.0 | ≥1.0.0 <2.0.0 | try it |
* | any version | any version | try it |
1.* | ≥1.0.0 <2.0.0 | ≥1.0.0 <2.0.0 | try it |
1.2.* | ≥1.2.0 <1.3.0 | ≥1.2.0 <1.3.0 | try it |
=1.2.3 | exactly 1.2.3 | exactly 1.2.3 | try it |
=1.2not exact! | ≥1.2.0 <1.3.0 | ≥1.2.0 <1.3.0 | try it |
>1.2 | ≥1.3.0 | ≥1.3.0 | try it |
<=2.3 | <2.4.0 | <2.4.0 | try it |
>=1.2, <1.5npm uses a space, not a comma | >=1.2, <1.5≥1.2.0 <1.5.0 | >=1.2 <1.5≥1.2.0 <1.5.0 | try it |
Ranges shown for release versions. Cargo only matches a pre-release such as 1.3.0-rc.1 when the requirement itself names a pre-release on the same version; see the
checker.
"1.2.3" in Cargo.toml is a minimum with caret updates, not a pin. Your Cargo.lock is what pins."0.8" never upgrades you to 0.9.~ in Cargo behaves like npm's tilde, not like Composer's or Ruby's ~>: see tilde vs caret and ~> vs ~= vs ~.It is the caret requirement ^1.0: any version ≥1.0.0 and <2.0.0. Cargo will pick the newest compatible 1.x release when it resolves the lock file.
Write "=1.2.3". Note that "=1.2" is not exact: it allows every 1.2.x (≥1.2.0 <1.3.0).
Below 1.0.0 the caret keeps the first non-zero number fixed, because Cargo treats a 0.x minor bump as breaking. "0.8.5" = ≥0.8.5 <0.9.0 and "0.0.3" = exactly the 0.0.3 line (<0.0.4).
No. Cargo rejects || and 1.2 - 2.3. Combine comparisons with a comma instead: ">=1.2, <1.5".
^ and ~ into [project] dependencies (Poetry 2, uv)