How to deal with deprecated APIs?


I’m currently following this neat tutorial about writing roguelike games in Rust.

In part 12 in the link, weighted distributions are used to generate NPCs with a given ratio.

use rand::distributions::{Weighted, WeightedChoice, IndependentSample};

The tutorial uses the rand module with version 0.3 whereas in the current version “0.6.5” all of the three imports given above are deprecated. The RLS linter hints to use rand::distributions::WeightedIndex instead of WeightedChoice. However I have no idea how to properly replace Weighted and IndependentSample without a significant amount of research, which I’m still not done with.

What is the Rust-conform way of dealing with changing and deprecating API’s?
Should I just revert the rand module to 0.3 and use the outdated but working distributions?
Should I take a deep dive into the documentation and figure out how to emulate the old methods with the new API? Is there any documentation on API changes and how change the old code to remain compatible with the new library version?

This is something that has been bothering me for a while about Rust because this is not the first time I’m confronted with changing library APIs and now I would like to hear from professional rustaceans what to do.


Update to the newest rand and follow the deprecated description.

  • warning: use of deprecated item rand::distributions::WeightedChoice: use WeightedIndex instead
  • warning: use of deprecated item rand::distributions::Weighted: use WeightedIndex instead

Sorry for not replying to your answer. I managed to get it to work using WeightedIndex, you are right on that. Originally I was looking for general advice on how to deal with changing APIs but I guess there is no real way around digging into the documentation and replacing the old code on a case by case basis.