Shepmaster
Shepmaster

Reputation: 430673

How do I import multiple versions of the same crate?

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?

Upvotes: 17

Views: 8342

Answers (1)

Shepmaster
Shepmaster

Reputation: 430673

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:

Upvotes: 35

Related Questions