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 Answer
As of Rust 1.31, you can rename dependencies in Cargo.toml:
[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:
2 Comments
joshlf
Is it possible to do this before Rust 1.31?
sffc
Just so others don't waste their time trying, this only works if the major versions are different. Different minor versions with the same major version (like "~1.2" and "~1.3" or "=0.6.0" and "=0.6.5") are fundamentally incompatible with cargo.