Update guessing game to rand 0.10#4680
Closed
sengmonkham wants to merge 1 commit into
Closed
Conversation
Migrate all ch02 guessing game listings from rand 0.8.5 to rand 0.10. API changes applied: - rand::thread_rng() -> rand::rng() - .gen_range(1..=100) -> .random_range(1..=100) - use rand::Rng -> use rand::RngExt (random_range moved to RngExt in 0.10) - rand = "0.8.5" -> rand = "0.10" in all Cargo.toml files Files changed: - 8x Cargo.toml (version bump) - 8x Cargo.lock (regenerated, pinning rand v0.10.0) - 7x src/main.rs (API calls updated) - src/ch02-00-guessing-game-tutorial.md (prose + console output updated) - src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md (prose updated)
|
Thanks for this PR. I started studying Rust and I was stuck at this step |
|
@sengmonkham: Could you please resolve the lint issues so this can be ready for merge? This change is particularly helpful for anyone new to the Rust ecosystem and is using the rust-book as their starting point. The example in the book still reflects an older API, which was updated in the Feb 2021 release. Aligning the code with the current API will make the learning experience smoother and avoid confusion for beginners. Thanks in advance! |
|
... or just use: let secret_number = rand::random_range(1..=100); |
Member
|
This is a duplicate of #4756. Please check existing pull requests before duplicating work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: #4679
Fixes the ch02 guessing game chapter, which was using
rand 0.8.5with APIs that have since been renamed inrand 0.9andrand 0.10.What changed
rand API migration:
rand 0.8.5)rand 0.10)rand = "0.8.5"rand = "0.10"use rand::Rnguse rand::RngExtrand::thread_rng().gen_range(1..=100)rand::rng().random_range(1..=100)Files updated:
listings/ch02-guessing-game-tutorial/*/Cargo.toml— version bump (×8)listings/ch02-guessing-game-tutorial/*/Cargo.lock— regenerated, pinningrand v0.10.0(×8)listings/ch02-guessing-game-tutorial/*/src/main.rs— API calls updated (×7)src/ch02-00-guessing-game-tutorial.md— prose, version specifiers, andcargo buildconsole output updatedsrc/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md— updatedrand::thread_rng/Rngreferences