18

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 1

36

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:

Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to do this before Rust 1.31?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.