【问题标题】:How do I import multiple versions of the same crate?如何导入同一个 crate 的多个版本?
【发布时间】:2019-11-07 13:21:28
【问题描述】:

正如Is it documented that Cargo can download and bundle multiple versions of the same crate? 中所讨论的,Cargo 可以为单个程序引入同一个 crate 的多个版本。如何同时访问这两个版本?

【问题讨论】:

    标签: rust rust-cargo


    【解决方案1】:

    截至Rust 1.31,您可以使用rename-dependency Cargo 功能:

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

    您可以为密钥选择任何您想要的名称。 package 属性必须是 crate 的正式名称。

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

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-23
      • 2011-07-13
      • 1970-01-01
      • 2015-01-24
      • 2013-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多