Cargo version dependency picking algorithm?

Is that the same

[dependencies]
for_each = "0.1"

as

[dependencies]
for_each = "0.1.2"

And

[dependencies]
for_each = "~0.1"

From description, it looks like the same, but from experimentation I am getting inconsistent results.

What is the subtle difference between those 3 variants of requiring dependencies?

See Specifying Dependencies - The Cargo Book

1.2.3   :=  >=1.2.3, <2.0.0
1.2     :=  >=1.2.0, <2.0.0
~1.2    :=  >=1.2.0, <1.3.0

Thanks, but what about versions which starts from 0.*? It's quite different for 0.*. No?

The versions "0.1" and "~0.1" are exactly the same. The version "0.1.2" is different in that it doesn't allow the versions 0.1.0 and 0.1.1, so if another crate requires something like "=0.1.1", then you will fail to compile with "0.1.2", whereas "0.1" would compile it using 0.1.1.

2 Likes

Ah. Yes, it is different. From the cargo book:

0.2.3  :=  >=0.2.3, <0.3.0
0.2    :=  >=0.2.0, <0.3.0

~0.2 is not directly presented an example, I believe it's equivalent to 0.2

1 Like

It looks like ranges are:

0.1    :=  >=0.1.0, <0.2.0
0.1.2  :=  >=0.1.2, <0.2.0
~0.1   := >=0.1.0, <0.2.0

Right?

From these, it's clear that 0.1 and ~0.1 have the same range.
But I encountered a situation when 0.1 and ~0.1 give very different results.
Some subtle difference beyond ranges exists, and I don't understand what is that.

Mind provide a minimum reproducible example Cargo.toml? Maybe we can find out what's wrong.

1 Like

That's difficult to isolate. I am trying.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.