Question on dependencies versions

I see on this page Specifying Dependencies - The Cargo Book

1.2.3  :=  >=1.2.3, <2.0.0
1.2    :=  >=1.2.0, <2.0.0
1      :=  >=1.0.0, <2.0.0
0.2.3  :=  >=0.2.3, <0.3.0
0.2    :=  >=0.2.0, <0.3.0
0.0.3  :=  >=0.0.3, <0.0.4
0.0    :=  >=0.0.0, <0.1.0
0      :=  >=0.0.0, <1.0.0

But for me, it should be something like that

1.2.3  :=  >=1.2.3, <1.3.0
1.2    :=  >=1.2.0, <2.0.0
1      :=  >=1.0.0, <2.0.0
0.2.3  :=  >=0.2.3, <0.3.0
0.2    :=  >=0.2.0, <1.0.0
0.0.3  :=  >=0.0.3, <0.1.0
0.0    :=  >=0.0.0, <1.0.0
0      :=  >=0.0.0, <1.0.0

Diff

version My understanding The docs
1.2.3 := >=1.2.3, <1.3.0 >=1.2.3, <2.0.0
1.2 := >=1.2.0, <2.0.0 >=1.2.0, <2.0.0
1 := >=1.0.0, <2.0.0 >=1.0.0, <2.0.0
0.2.3 := >=0.2.3, <0.3.0 >=0.2.3, <0.3.0
0.2 := >=0.2.0, <1.0.0 >=0.2.0, <0.3.0
0.0.3 := >=0.0.3, <0.1.0 >=0.0.3, <0.0.4
0.0 := >=0.0.0, <1.0.0 >=0.0.0, <0.1.0
0 := >=0.0.0, <1.0.0 >=0.0.0, <1.0.0

Where is my mistake ?

Cargo's interpretation of major version is unusual. It's not the first number, but the first non-zero number.

0.0.1 is a semver-major version 1 with no minor version and no patch version.

Apart from that, the ^ operator is the implied default meaning that it upgrades minor and patch versions.

Okay but what about the first case

1.2.3 := 

# for me it should be
>=1.2.3, <1.3.0


# per doc it is
>=1.2.3, <2.0.0

That would be a tilde requirement, ~1.2.3 := >=1.2.3, <1.3.0.

1 Like

1.2.0 giving <2.0.0 is the ^ operator.

It's the default, because minor changes are considered non-breaking when upgrading.

Okay thanks !

Note that the docs discourage ~ and other operators except in specific circustances because cargo unifies compatible versions across the dependency tree and if a package has a non-semver upper bound then it is incompatible with packages that use newer versions, causing errors and frustrating users.

1 Like