Skip to content

Commit

Permalink
update original
Browse files Browse the repository at this point in the history
  • Loading branch information
funkill committed May 28, 2024
1 parent 0b0c9af commit 44b9a91
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ struct ImportantExcerpt<'a> {

fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let first_sentence = novel.split('.').next().unwrap();
let i = ImportantExcerpt {
part: first_sentence,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a> ImportantExcerpt<'a> {

fn main() {
let novel = String::from("Call me Ishmael. Some years ago...");
let first_sentence = novel.split('.').next().expect("Could not find a '.'");
let first_sentence = novel.split('.').next().unwrap();
let i = ImportantExcerpt {
part: first_sentence,
};
Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/packages/mdbook-trpl-listing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Preprocessor for TrplListing {
}

fn supports_renderer(&self, renderer: &str) -> bool {
renderer == "html"
renderer == "html" || renderer == "markdown"
}
}

Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/packages/mdbook-trpl-note/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Preprocessor for TrplNote {
}

fn supports_renderer(&self, renderer: &str) -> bool {
renderer == "html"
renderer == "html" || renderer == "markdown"
}
}

Expand Down
2 changes: 1 addition & 1 deletion rustbook-en/packages/tools/src/bin/remove_markup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn remove_markup(input: String) -> String {
let caption_start_regex =
Regex::new(r#"\A<span class="caption">(.*)\z"#).unwrap();
let caption_end_regex = Regex::new(r#"(.*)</span>\z"#).unwrap();
let regexen = vec![filename_regex, caption_start_regex, caption_end_regex];
let regexen = [filename_regex, caption_start_regex, caption_end_regex];

let lines: Vec<_> = input
.lines()
Expand Down
23 changes: 11 additions & 12 deletions rustbook-en/src/ch02-00-guessing-game-tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -682,13 +682,12 @@ in the expression refers to the original `guess` variable that contained the
input as a string. The `trim` method on a `String` instance will eliminate any
whitespace at the beginning and end, which we must do to be able to compare the
string to the `u32`, which can only contain numerical data. The user must press
<span class="keystroke">enter</span> to satisfy `read_line` and input their
guess, which adds a newline character to the string. For example, if the user
types <span class="keystroke">5</span> and presses <span
class="keystroke">enter</span>, `guess` looks like this: `5\n`. The `\n`
represents “newline.” (On Windows, pressing <span
class="keystroke">enter</span> results in a carriage return and a newline,
`\r\n`.) The `trim` method eliminates `\n` or `\r\n`, resulting in just `5`.
<kbd>enter</kbd> to satisfy `read_line` and input their guess, which adds a
newline character to the string. For example, if the user types <kbd>5</kbd> and
presses <kbd>enter</kbd>, `guess` looks like this: `5\n`. The `\n` represents
“newline.” (On Windows, pressing <kbd>enter</kbd> results in a carriage return
and a newline, `\r\n`.) The `trim` method eliminates `\n` or `\r\n`, resulting
in just `5`.

The [`parse` method on strings][parse]<!-- ignore --> converts a string to
another type. Here, we use it to convert from a string to a number. We need to
Expand Down Expand Up @@ -762,11 +761,11 @@ and run the program again. The program will now ask for another guess forever,
which actually introduces a new problem. It doesn’t seem like the user can quit!

The user could always interrupt the program by using the keyboard shortcut
<span class="keystroke">ctrl-c</span>. But there’s another way to escape this
insatiable monster, as mentioned in the `parse` discussion in [“Comparing the
Guess to the Secret Number”](#comparing-the-guess-to-the-secret-number)<!--
ignore -->: if the user enters a non-number answer, the program will crash. We
can take advantage of that to allow the user to quit, as shown here:
<kbd>ctrl</kbd>-<kbd>c</kbd>. But there’s another way to escape this insatiable
monster, as mentioned in the `parse` discussion in [“Comparing the Guess to the
Secret Number”](#comparing-the-guess-to-the-secret-number)<!-- ignore -->: if
the user enters a non-number answer, the program will crash. We can take
advantage of that to allow the user to quit, as shown here:

<!-- manual-regeneration
cd listings/ch02-guessing-game-tutorial/no-listing-04-looping/
Expand Down
13 changes: 6 additions & 7 deletions rustbook-en/src/ch03-05-control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ like this:
```

When we run this program, we’ll see `again!` printed over and over continuously
until we stop the program manually. Most terminals support the keyboard
shortcut <span class="keystroke">ctrl-c</span> to interrupt a program that is
stuck in a continual loop. Give it a try:
until we stop the program manually. Most terminals support the keyboard shortcut
<kbd>ctrl</kbd>-<kdb>c</kbd> to interrupt a program that is stuck in a continual
loop. Give it a try:

<!-- manual-regeneration
cd listings/ch03-common-programming-concepts/no-listing-32-loop
Expand All @@ -213,10 +213,9 @@ again!
^Cagain!
```

The symbol `^C` represents where you pressed <span
class="keystroke">ctrl-c</span>. You may or may not see the word `again!`
printed after the `^C`, depending on where the code was in the loop when it
received the interrupt signal.
The symbol `^C` represents where you pressed <kbd>ctrl</kbd>-<kbd>c</kbd>. You
may or may not see the word `again!` printed after the `^C`, depending on where
the code was in the loop when it received the interrupt signal.

Fortunately, Rust also provides a way to break out of a loop using code. You
can place the `break` keyword within the loop to tell the program when to stop
Expand Down
8 changes: 4 additions & 4 deletions rustbook-en/src/ch20-01-single-threaded.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ part of the `drop` implementation. Browsers sometimes deal with closed
connections by retrying, because the problem might be temporary. The important
factor is that we’ve successfully gotten a handle to a TCP connection!

Remember to stop the program by pressing <span class="keystroke">ctrl-c</span>
when you’re done running a particular version of the code. Then restart the
program by invoking the `cargo run` command after you’ve made each set of code
changes to make sure you’re running the newest code.
Remember to stop the program by pressing <kbd>ctrl</kbd>-<kbd>c</kbd> when
you’re done running a particular version of the code. Then restart the program
by invoking the `cargo run` command after you’ve made each set of code changes
to make sure you’re running the newest code.

### Reading the Request

Expand Down
8 changes: 4 additions & 4 deletions rustbook-en/src/ch20-03-graceful-shutdown-and-cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
The code in Listing 20-20 is responding to requests asynchronously through the
use of a thread pool, as we intended. We get some warnings about the `workers`,
`id`, and `thread` fields that we’re not using in a direct way that reminds us
we’re not cleaning up anything. When we use the less elegant <span
class="keystroke">ctrl-c</span> method to halt the main thread, all other
threads are stopped immediately as well, even if they’re in the middle of
serving a request.
we’re not cleaning up anything. When we use the less elegant
<kbd>ctrl</kbd>-<kbd>c</kbd> method to halt the main thread, all other threads
are stopped immediately as well, even if they’re in the middle of serving a
request.

Next, then, we’ll implement the `Drop` trait to call `join` on each of the
threads in the pool so they can finish the requests they’re working on before
Expand Down
8 changes: 8 additions & 0 deletions rustbook-en/tools/nostarch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ set -eu

cargo build --release

cd packages/mdbook-trpl-listing
cargo install --locked --path .

cd ../mdbook-trpl-note
cargo install --locked --path .

cd ../..

mkdir -p tmp
rm -rf tmp/*.md
rm -rf tmp/markdown
Expand Down

0 comments on commit 44b9a91

Please sign in to comment.