How to specify the exact version of a dependency?
Exact versions are prepended by =
. It's one of the comparison requirements (formerly called inequality requirement).
lazy_static = "= 0.2.2"
The default is the caret requirement (e.g. 0.2.2
is equivalent to ^0.2.2
), which accepts minor and patch version updates (or just patch updates if the major is 0
). Unless you have a very good reason to disallow this, it is often recommended to leave the default specifier as it is.
TL;DR:
my-crate = "=1.2.3"
Reading the documentation is generally a great idea. In this case, the Cargo documentation has an entire section on specifying dependencies:
Since this string does not have any operators in it, it is interpreted the same way as if we had specified
"^0.1.12"
, which is called a caret requirement.Caret requirements allow SemVer compatible updates to a specified version. An update is allowed if the new version number does not modify the left-most non-zero digit in the major, minor, patch grouping.
As well as
Inequality requirements allow manually specifying a version range or an exact version to depend on.
Here are some examples of inequality requirements:
= 1.2.3
What am I doing wrong?
I'd say that, without extenuating circumstances, trying to specify an exact version is wrong. There's generally very little reason to force the users of your code to be stuck to an older version of a crate and prevent them from getting bug fixes.
Cargo.lock is the correct tool to avoid deploying your application with an inconsistent set of dependencies.