如何导入同一个 crate 的多个版本? [英] How do I import multiple versions of the same crate?

查看:48
本文介绍了如何导入同一个 crate 的多个版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有记录表明 Cargo 可以下载和捆绑同一个 crate 的多个版本?,有可能Cargo 为单个程序拉取同一个 crate 的多个版本.如何同时访问这两个版本?

As discussed in Is it documented that Cargo can download and bundle multiple versions of the same crate?, it's possible for Cargo to pull in multiple versions of the same crate for a single program. How do I access both of these versions concurrently?

推荐答案

截至 Rust 1.31,你可以使用 重命名依赖 Cargo 功能:

As of Rust 1.31, you can use the rename-dependency Cargo feature:

[dependencies]
futures-01 = { package = "futures", version = "0.1.0" }
futures-03 = { package = "futures", version = "0.3.0" }

您可以为密钥选择任何您想要的名称.package 属性需要是 crate 的官方名称.

You can choose whatever name you want for the key. The package attribute needs to be the official name of the crate.

在您的代码中,您可以使用 crate 名称 futures_01 访问 0.1.x 版,通过 futures_03 访问 0.3.x 版.

Within your code, you can access version 0.1.x using the crate name futures_01, and version 0.3.x via futures_03.

另见:

这篇关于如何导入同一个 crate 的多个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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