How do I import multiple versions of the same crate?

a 夏天 提交于 2019-12-31 04:23:04

问题


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?


回答1:


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" }

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

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

See also:

  • How to idiomatically alias a crate in Rust 2018?
  • Why is a trait not implemented for a type that clearly has it implemented?


来源:https://stackoverflow.com/questions/58739075/how-do-i-import-multiple-versions-of-the-same-crate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!