Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax for specifying dependency versions in Cargo?

Tags:

So far I have seen three...

[dependencies]
crate = "1.0.0"  # I think this is an exact version match
crate = "^1.0.0" # I think this means "use that latest 1.x.x"
crate = "*"      # I think this means "use the latest"

I'd love to know for certain how to use the dependency list. It would be nice to have an authoritative source that documents the different syntaxes for dependencies.

like image 276
jocull Avatar asked Jun 14 '15 06:06

jocull


People also ask

What are dependencies in Rust?

The [dependencies] section lets you add dependencies for your project. For example, suppose that we want our program to have a great CLI. You can find lots of great packages on crates.io (the official Rust package registry).

Where are cargo dependencies stored?

registry/cache Downloaded dependencies are stored in the cache. The crates are compressed gzip archives named with a . crate extension. registry/src If a downloaded .

Does updating dependencies using cargo guarantee that you use the latest version of the dependency?

This means that only the dependency specified by SPEC will be updated. Its transitive dependencies will be updated only if SPEC cannot be updated without updating dependencies. All other dependencies will remain locked at their currently recorded versions. If -p is not specified, all dependencies are updated.


1 Answers

See the crates.io documentation page on "Specifying Dependencies". To summarise:

  • Nothing or a caret (^) means "at least this version, until the next incompatible version".

  • A tilde (~) means "at least this version, until (but excluding) the next minor/major release". That is, ~1.2.3 will accept 1.2.X where X is at least 3, ~1.2 will accept 1.2.*, and ~1 will accept 1.*.*.

  • A wildcard (*) means "anything that looks like this". That is, 1.2.* will accept 1.2.anything (1.2.0, 1.2.7-beta, 1.2.93-dev.foo, etc. but not 1.3.0).

  • Inequalities (>=, >, <, =) mean the obvious: the version Cargo uses must satisfy the given inequality.

like image 179
DK. Avatar answered Sep 21 '22 11:09

DK.