How do I import multiple versions of the same crate?

后端 未结 1 1200
时光说笑
时光说笑 2021-01-21 15:15

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

相关标签:
1条回答
  • 2021-01-21 15:37

    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?
    0 讨论(0)
提交回复
热议问题