在 Cargo 中指定依赖版本的语法是什么? [英] What is the syntax for specifying dependency versions in Cargo?

查看:40
本文介绍了在 Cargo 中指定依赖版本的语法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经看到了三个......

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.

推荐答案

参见 crates.io 文档页面指定依赖项".总结:

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

  • Nothing 或插入符号 (^) 表示至少是这个版本,直到下一个不兼容的版本".

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

波浪号 (~) 表示至少是这个版本,直到(但不包括)下一个次要/主要版本".也就是说,~1.2.3 将接受 1.2.X 其中 X 是至少3个,~1.2会接受1.2.*~1会接受1.*.*.

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.*.*.

通配符 (*) 表示任何看起来像这样的东西".也就是说,1.2.* 将接受 1.2.anything (1.2.0, 1.2.7-beta1.2.93-dev.foo 等,但不包括 1.3.0).

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).

不等式(>=><=)意味着显而易见:Cargo 使用的版本必须满足给定的不等式.

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

这篇关于在 Cargo 中指定依赖版本的语法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆