如何导入同一个 crate 的多个版本?

How do I import multiple versions of the same crate?

正如 中所讨论的,Cargo 可以为单个程序引入同一个 crate 的多个版本。如何同时访问这两个版本?

截至 Rust 1.31, you can use the rename-dependency 货运功能:

[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.[=17= 访问版本 0.3.x ]

另请参阅: