Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ retweet
rewordings
rint
ripgrep
RngExt
Rumbul
runnable
runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::io;

// ANCHOR: ch07-04
use rand::Rng;
use rand::RngExt;

fn main() {
// ANCHOR_END: ch07-04
println!("Guess the number!");

// ANCHOR: ch07-04
let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);
// ANCHOR_END: ch07-04

println!("The secret number is: {secret_number}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
// --snip--
// ANCHOR_END: here
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

loop {
println!("Please input your guess.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

// ANCHOR: here
// --snip--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::cmp::Ordering;
use std::io;

use rand::Rng;
use rand::RngExt;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::Rng;
use rand::RngExt;
// ANCHOR: here
// --snip--
use std::{cmp::Ordering, io};
Expand All @@ -8,7 +8,7 @@ use std::{cmp::Ordering, io};
fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2024"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rand::Rng;
use rand::RngExt;
// ANCHOR: here
// --snip--
use std::cmp::Ordering;
Expand All @@ -9,7 +9,7 @@ use std::io;
fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

println!("The secret number is: {secret_number}");

Expand Down
2 changes: 1 addition & 1 deletion listings/ch09-error-handling/listing-09-13/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
4 changes: 2 additions & 2 deletions listings/ch09-error-handling/listing-09-13/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use guessing_game::Guess;
use rand::Rng;
use rand::RngExt;
use std::cmp::Ordering;
use std::io;

Expand All @@ -8,7 +8,7 @@ mod guessing_game;
fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

loop {
println!("Please input your guess.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use rand::Rng;
use rand::RngExt;
use std::cmp::Ordering;
use std::io;

fn main() {
println!("Guess the number!");

let secret_number = rand::thread_rng().gen_range(1..=100);
let secret_number = rand::rng().random_range(1..=100);

// ANCHOR: here
loop {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2024"

[dependencies]
rand = "0.8.5"
rand = "0.10.1"
2 changes: 1 addition & 1 deletion src/ch01-01-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ what `cargo` is and what each of these commands does in detail later.)
```console
$ cargo new get-dependencies
$ cd get-dependencies
$ cargo add rand@0.8.5 trpl@0.2.0
$ cargo add rand@0.10.1 trpl@0.2.0
```

This will cache the downloads for these packages so you will not need to
Expand Down
42 changes: 21 additions & 21 deletions src/ch02-00-guessing-game-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ In the _Cargo.toml_ file, everything that follows a header is part of that
section that continues until another section starts. In `[dependencies]`, you
tell Cargo which external crates your project depends on and which versions of
those crates you require. In this case, we specify the `rand` crate with the
semantic version specifier `0.8.5`. Cargo understands [Semantic
semantic version specifier `0.10.1`. Cargo understands [Semantic
Versioning][semver]<!-- ignore --> (sometimes called _SemVer_), which is a
standard for writing version numbers. The specifier `0.8.5` is actually
shorthand for `^0.8.5`, which means any version that is at least 0.8.5 but
below 0.9.0.
standard for writing version numbers. The specifier `0.10.1` is actually
shorthand for `^0.10.1`, which means any version that is at least 0.10.1 but
below 0.11.0.

Cargo considers these versions to have public APIs compatible with version
0.8.5, and this specification ensures that you’ll get the latest patch release
that will still compile with the code in this chapter. Any version 0.9.0 or
0.10.1, and this specification ensures that you’ll get the latest patch release
that will still compile with the code in this chapter. Any version 0.11.0 or
greater is not guaranteed to have the same API as what the following examples
use.

Expand All @@ -386,7 +386,7 @@ cargo build -->
$ cargo build
Updating crates.io index
Locking 15 packages to latest Rust 1.85.0 compatible versions
Adding rand v0.8.5 (available: v0.9.0)
Adding rand v0.10.1 (available: v0.11.0)
Compiling proc-macro2 v1.0.93
Compiling unicode-ident v1.0.17
Compiling libc v0.2.170
Expand All @@ -400,7 +400,7 @@ $ cargo build
Compiling zerocopy v0.7.35
Compiling ppv-lite86 v0.2.20
Compiling rand_chacha v0.3.1
Compiling rand v0.8.5
Compiling rand v0.10.1
Compiling guessing_game v0.1.0 (file:///projects/guessing_game)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.48s
```
Expand Down Expand Up @@ -455,7 +455,7 @@ reuse what it has already downloaded and compiled for those.
Cargo has a mechanism that ensures that you can rebuild the same artifact every
time you or anyone else builds your code: Cargo will use only the versions of
the dependencies you specified until you indicate otherwise. For example, say
that next week version 0.8.6 of the `rand` crate comes out, and that version
that next week version 0.10.2 of the `rand` crate comes out, and that version
contains an important bug fix, but it also contains a regression that will
break your code. To handle this, Rust creates the _Cargo.lock_ file the first
time you run `cargo build`, so we now have this in the _guessing_game_
Expand All @@ -467,7 +467,7 @@ _Cargo.lock_ file. When you build your project in the future, Cargo will see
that the _Cargo.lock_ file exists and will use the versions specified there
rather than doing all the work of figuring out versions again. This lets you
have a reproducible build automatically. In other words, your project will
remain at 0.8.5 until you explicitly upgrade, thanks to the _Cargo.lock_ file.
remain at 0.10.1 until you explicitly upgrade, thanks to the _Cargo.lock_ file.
Because the _Cargo.lock_ file is important for reproducible builds, it’s often
checked into source control with the rest of the code in your project.

Expand All @@ -477,8 +477,8 @@ When you _do_ want to update a crate, Cargo provides the command `update`,
which will ignore the _Cargo.lock_ file and figure out all the latest versions
that fit your specifications in _Cargo.toml_. Cargo will then write those
versions to the _Cargo.lock_ file. Otherwise, by default, Cargo will only look
for versions greater than 0.8.5 and less than 0.9.0. If the `rand` crate has
released the two new versions 0.8.6 and 0.999.0, you would see the following if
for versions greater than 0.10.1 and less than 0.11.0. If the `rand` crate has
released the two new versions 0.10.2 and 0.999.0, you would see the following if
you ran `cargo update`:

<!-- manual-regeneration
Expand All @@ -491,15 +491,15 @@ as a guide to creating the hypothetical output shown here -->
$ cargo update
Updating crates.io index
Locking 1 package to latest Rust 1.85.0 compatible version
Updating rand v0.8.5 -> v0.8.6 (available: v0.999.0)
Updating rand v0.10.1 -> v0.10.2 (available: v0.999.0)
```

Cargo ignores the 0.999.0 release. At this point, you would also notice a
change in your _Cargo.lock_ file noting that the version of the `rand` crate
you are now using is 0.8.6. To use `rand` version 0.999.0 or any version in the
you are now using is 0.10.2. To use `rand` version 0.999.0 or any version in the
0.999._x_ series, you’d have to update the _Cargo.toml_ file to look like this
instead (don’t actually make this change because the following examples assume
you’re using `rand` 0.8):
you’re using `rand` 0.10):

```toml
[dependencies]
Expand Down Expand Up @@ -529,17 +529,17 @@ update _src/main.rs_, as shown in Listing 2-3.

</Listing>

First, we add the line `use rand::Rng;`. The `Rng` trait defines methods that
First, we add the line `use rand::RngExt;`. The `RngExt` trait defines methods that
random number generators implement, and this trait must be in scope for us to
use those methods. Chapter 10 will cover traits in detail.

Next, we’re adding two lines in the middle. In the first line, we call the
`rand::thread_rng` function that gives us the particular random number
`rand::rng` function that gives us the particular random number
generator we’re going to use: one that is local to the current thread of
execution and is seeded by the operating system. Then, we call the `gen_range`
method on the random number generator. This method is defined by the `Rng`
trait that we brought into scope with the `use rand::Rng;` statement. The
`gen_range` method takes a range expression as an argument and generates a
execution and is seeded by the operating system. Then, we call the `random_range`
method on the random number generator. This method is defined by the `RngExt`
trait that we brought into scope with the `use rand::RngExt;` statement. The
`random_range` method takes a range expression as an argument and generates a
random number in the range. The kind of range expression we’re using here takes
the form `start..=end` and is inclusive on the lower and upper bounds, so we
need to specify `1..=100` to request a number between 1 and 100.
Expand Down
4 changes: 2 additions & 2 deletions src/ch07-04-bringing-paths-into-scope-with-the-use-keyword.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ make `rand` available to our project.
Then, to bring `rand` definitions into the scope of our package, we added a
`use` line starting with the name of the crate, `rand`, and listed the items we
wanted to bring into scope. Recall that in [“Generating a Random
Number”][rand]<!-- ignore --> in Chapter 2, we brought the `Rng` trait into
scope and called the `rand::thread_rng` function:
Number”][rand]<!-- ignore --> in Chapter 2, we brought the `RngExt` trait into
scope and called the `rand::rng` function:

```rust,ignore
{{#rustdoc_include ../listings/ch02-guessing-game-tutorial/listing-02-03/src/main.rs:ch07-04}}
Expand Down
Loading