▲ | 0xffff2 a day ago | ||||||||||||||||||||||||||||||||||
So there's no difference at all between "0", "0.9" and "0.9.3" in cargo.toml (Since semver says only major version numbers are breaking)? As a decently experienced Rust developer, that's deeply surprising to me. What if devs don't do a good job of versioning and there is a real incompatibility between 0.9.3 and 0.9.4? Surely there's some way to actually require an exact version? | |||||||||||||||||||||||||||||||||||
▲ | Diggsey 18 hours ago | parent | next [-] | ||||||||||||||||||||||||||||||||||
They are different:
Notice how the the minimum bound changes while the upper bound is the same for all of them.The reason for this is that unless otherwise specified, the ^ operator is used, so "0.9" is actually "^0.9", which then gets translated into the kind of range specifier I showed above. There are other operators you can use, these are the common ones:
Note that while an exact bound will force that exact version to be used, it still doesn't allow two semver compatible versions of a crate to exist together. For example. If cargo can't find a single version that satisfies all constraints, it will just error.For this reason, if you are writing a library, you should in almost all cases stick to regular semver-compatible dependency specifications. For binaries, it is more common to want exact control over versions and you don't have downstream consumers for whom your exact constraints would be a nightmare. | |||||||||||||||||||||||||||||||||||
▲ | a day ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||
[deleted] | |||||||||||||||||||||||||||||||||||
▲ | steveklabnik a day ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||
Note that in the output, there is rand 0.9.0, and two instances of rand_core 0.9.3. You may have thought it selected two versions because you missed the _core there. > So there's no difference at all between "0", "0.9" and "0.9.3" in cargo.toml No, there is a difference, in particular, they all specify different minimum bounds. The trick is that these are using the ^ operator to match, which means that the version "0.9.3" will satisfy all of those constraints, and so Cargo will select 0.9.3 (the latest version at the time I write this comment) as the one version to satisfy all of them. Cargo will only select multiple versions when it's not compatible, that is, if you had something like "1.0.0" and "0.9.0". > Surely there's some way to actually require an exact version? Yes, you'd have to use `=`, like `=0.9.3`. This is heavily discouraged because it would lead to a proliferation of duplication in dependency versions, which aren't necessarily unless you are trying to avoid some sort of specific bugfix. This is sometimes done in applications, but basically should never be done in libraries. | |||||||||||||||||||||||||||||||||||
|