Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed Apr 4, 2024
1 parent a2f2be8 commit 3145ecc
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion rustbook-en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,6 @@ before we merge any in, but feel free to start!
To scan source files for spelling errors, you can use the `spellcheck.sh`
script available in the `ci` directory. It needs a dictionary of valid words,
which is provided in `ci/dictionary.txt`. If the script produces a false
positive (say, you used word `BTreeMap` which the script considers invalid),
positive (say, you used the word `BTreeMap` which the script considers invalid),
you need to add this word to `ci/dictionary.txt` (keep the sorted order for
consistency).
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 || value > 100 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!(
"Guess value must be greater than or equal to 1, got {}.",
value
"Guess value must be greater than or equal to 1, got {value}."
);
} else if value > 100 {
panic!(
"Guess value must be less than or equal to 100, got {}.",
value
"Guess value must be less than or equal to 100, got {value}."
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Guess {
impl Guess {
pub fn new(value: i32) -> Guess {
if value < 1 {
panic!("Guess value must be between 1 and 100, got {}.", value);
panic!("Guess value must be between 1 and 100, got {value}.");
}

Guess { value }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ impl Guess {
// ANCHOR: here
if value < 1 {
panic!(
"Guess value must be less than or equal to 100, got {}.",
value
"Guess value must be less than or equal to 100, got {value}."
);
} else if value > 100 {
panic!(
"Guess value must be greater than or equal to 1, got {}.",
value
"Guess value must be greater than or equal to 1, got {value}."
);
}
// ANCHOR_END: here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $ cargo run
error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure
--> src/main.rs:18:30
|
15 | let value = String::from("by key called");
15 | let value = String::from("closure called");
| ----- captured outer variable
16 |
17 | list.sort_by_key(|r| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {
];

let mut sort_operations = vec![];
let value = String::from("by key called");
let value = String::from("closure called");

list.sort_by_key(|r| {
sort_operations.push(value);
Expand Down
4 changes: 2 additions & 2 deletions rustbook-en/src/ch13-01-closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ compiler won’t let us use this closure with `sort_by_key`:
`sort_by_key`</span>

This is a contrived, convoluted way (that doesn’t work) to try and count the
number of times `sort_by_key` gets called when sorting `list`. This code
number of times `sort_by_key` calls the closure when sorting `list`. This code
attempts to do this counting by pushing `value`—a `String` from the closure’s
environment—into the `sort_operations` vector. The closure captures `value`
then moves `value` out of the closure by transferring ownership of `value` to
Expand All @@ -399,7 +399,7 @@ implement `FnMut`:

The error points to the line in the closure body that moves `value` out of the
environment. To fix this, we need to change the closure body so that it doesn’t
move values out of the environment. To count the number of times `sort_by_key`
move values out of the environment. To count the number of times the closure
is called, keeping a counter in the environment and incrementing its value in
the closure body is a more straightforward way to calculate that. The closure
in Listing 13-9 works with `sort_by_key` because it is only capturing a mutable
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch15-02-deref.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ smart pointers to work in ways similar to references. Then we’ll look at
Rust’s *deref coercion* feature and how it lets us work with either references
or smart pointers.

> Note: there’s one big difference between the `MyBox<T>` type we’re about to
> Note: There’s one big difference between the `MyBox<T>` type we’re about to
> build and the real `Box<T>`: our version will not store its data on the heap.
> We are focusing this example on `Deref`, so where the data is actually stored
> is less important than the pointer-like behavior.
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/src/ch20-02-multithreaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ overloaded if the server receives a lot of requests. If we make a request to
*/sleep*, the server will be able to serve other requests by having another
thread run them.

> Note: if you open */sleep* in multiple browser windows simultaneously, they
> Note: If you open */sleep* in multiple browser windows simultaneously, they
> might load one at a time in 5 second intervals. Some web browsers execute
> multiple instances of the same request sequentially for caching reasons. This
> limitation is not caused by our web server.
Expand Down

0 comments on commit 3145ecc

Please sign in to comment.