diff --git a/rustbook-en/.github/workflows/main.yml b/rustbook-en/.github/workflows/main.yml index 1737bce00..2b3ae3d5c 100644 --- a/rustbook-en/.github/workflows/main.yml +++ b/rustbook-en/.github/workflows/main.yml @@ -12,8 +12,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.79 -c rust-docs - rustup default 1.79 + rustup toolchain install 1.81 -c rust-docs + rustup default 1.81 - name: Install mdbook run: | mkdir bin @@ -36,8 +36,8 @@ jobs: - name: Install Rust run: | rustup set profile minimal - rustup toolchain install 1.79 -c rust-docs - rustup default 1.79 + rustup toolchain install 1.81 -c rust-docs + rustup default 1.81 - name: Run `tools` package tests run: | cargo test diff --git a/rustbook-en/README.md b/rustbook-en/README.md index 8befc1b31..9648db0ae 100644 --- a/rustbook-en/README.md +++ b/rustbook-en/README.md @@ -33,6 +33,16 @@ rust-lang/rust uses in [this file][rust-mdbook]. To get it: $ cargo install mdbook --locked --version ``` +The book also uses two mdbook plugins which are part of this repository. If you +do not install them, you will see warnings when building and the output will not +look right, but you *will* still be able to build the book. To use the plugins, +you should run: + +```bash +$ cargo install --locked --path packages/mdbook-trpl-listing +$ cargo install --locked --path packages/mdbook-trpl-note +``` + ## Building To build the book, type: diff --git a/rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt b/rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt index bb997866a..0f0bc2102 100644 --- a/rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt +++ b/rustbook-en/listings/ch02-guessing-game-tutorial/listing-02-04/output.txt @@ -1,4 +1,10 @@ $ cargo build + Downloading crates ... + Downloaded rand_core v0.6.2 + Downloaded getrandom v0.2.2 + Downloaded rand_chacha v0.3.0 + Downloaded ppv-lite86 v0.2.10 + Downloaded libc v0.2.86 Compiling libc v0.2.86 Compiling getrandom v0.2.2 Compiling cfg-if v1.0.0 @@ -18,7 +24,7 @@ error[E0308]: mismatched types = note: expected reference `&String` found reference `&{integer}` note: method defined here - --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/cmp.rs:840:8 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/cmp.rs:839:8 For more information about this error, try `rustc --explain E0308`. error: could not compile `guessing_game` (bin "guessing_game") due to 1 previous error diff --git a/rustbook-en/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt b/rustbook-en/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt index 73ca9d62f..85efb431e 100644 --- a/rustbook-en/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt +++ b/rustbook-en/listings/ch03-common-programming-concepts/no-listing-01-variables-are-immutable/output.txt @@ -4,13 +4,15 @@ error[E0384]: cannot assign twice to immutable variable `x` --> src/main.rs:4:5 | 2 | let x = 5; - | - - | | - | first assignment to `x` - | help: consider making this binding mutable: `mut x` + | - first assignment to `x` 3 | println!("The value of x is: {x}"); 4 | x = 6; | ^^^^^ cannot assign twice to immutable variable + | +help: consider making this binding mutable + | +2 | let mut x = 5; + | +++ For more information about this error, try `rustc --explain E0384`. error: could not compile `variables` (bin "variables") due to 1 previous error diff --git a/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt b/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt index dde05f4b3..1eb76de43 100644 --- a/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt +++ b/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-07-cant-use-option-directly/output.txt @@ -8,10 +8,10 @@ error[E0277]: cannot add `Option` to `i8` | = help: the trait `Add>` is not implemented for `i8` = help: the following other types implement trait `Add`: - <&'a i8 as Add> - <&i8 as Add<&i8>> - > - + `&'a i8` implements `Add` + `&i8` implements `Add<&i8>` + `i8` implements `Add<&i8>` + `i8` implements `Add` For more information about this error, try `rustc --explain E0277`. error: could not compile `enums` (bin "enums") due to 1 previous error diff --git a/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt b/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt index 5232f9037..43acd14d6 100644 --- a/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt +++ b/rustbook-en/listings/ch06-enums-and-pattern-matching/no-listing-10-non-exhaustive-match/output.txt @@ -7,8 +7,8 @@ error[E0004]: non-exhaustive patterns: `None` not covered | ^ pattern `None` not covered | note: `Option` defined here - --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:571:1 - ::: /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/core/src/option.rs:575:5 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:574:1 + ::: /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/core/src/option.rs:578:5 | = note: not covered = note: the matched value is of type `Option` diff --git a/rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt b/rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt index dbc9bb13d..f3c1641b2 100644 --- a/rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt +++ b/rustbook-en/listings/ch09-error-handling/listing-09-10/output.txt @@ -9,6 +9,14 @@ error[E0277]: the `?` operator can only be used in a function that returns `Resu | ^ cannot use the `?` operator in a function that returns `()` | = help: the trait `FromResidual>` is not implemented for `()` +help: consider adding return type + | +3 ~ fn main() -> Result<(), Box> { +4 | let greeting_file = File::open("hello.txt")?; +5 + +6 + Ok(()) +7 + } + | For more information about this error, try `rustc --explain E0277`. error: could not compile `error-handling` (bin "error-handling") due to 1 previous error diff --git a/rustbook-en/listings/ch13-functional-features/listing-13-04/output.txt b/rustbook-en/listings/ch13-functional-features/listing-13-04/output.txt index b04a1a36c..fbc00b5df 100644 --- a/rustbook-en/listings/ch13-functional-features/listing-13-04/output.txt +++ b/rustbook-en/listings/ch13-functional-features/listing-13-04/output.txt @@ -1,6 +1,6 @@ $ cargo run Locking 1 package to latest compatible version - Adding closure-example v0.1.0 (/Users/carolnichols/rust/book/tmp/listings/ch13-functional-features/listing-13-04) + Adding closure-example v0.1.0 (/Users/chris/dev/rust-lang/book/tmp/listings/ch13-functional-features/listing-13-04) Compiling closure-example v0.1.0 (file:///projects/closure-example) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/closure-example` diff --git a/rustbook-en/listings/ch13-functional-features/listing-13-05/output.txt b/rustbook-en/listings/ch13-functional-features/listing-13-05/output.txt index 1fddf5a98..695ee4bee 100644 --- a/rustbook-en/listings/ch13-functional-features/listing-13-05/output.txt +++ b/rustbook-en/listings/ch13-functional-features/listing-13-05/output.txt @@ -1,6 +1,6 @@ $ cargo run Locking 1 package to latest compatible version - Adding closure-example v0.1.0 (/Users/carolnichols/rust/book/tmp/listings/ch13-functional-features/listing-13-05) + Adding closure-example v0.1.0 (/Users/chris/dev/rust-lang/book/tmp/listings/ch13-functional-features/listing-13-05) Compiling closure-example v0.1.0 (file:///projects/closure-example) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.43s Running `target/debug/closure-example` diff --git a/rustbook-en/listings/ch15-smart-pointers/listing-15-21/output.txt b/rustbook-en/listings/ch15-smart-pointers/listing-15-21/output.txt index 3509e8ec6..8501007f0 100644 --- a/rustbook-en/listings/ch15-smart-pointers/listing-15-21/output.txt +++ b/rustbook-en/listings/ch15-smart-pointers/listing-15-21/output.txt @@ -10,7 +10,7 @@ help: consider changing this to be a mutable reference in the `impl` method and | 2 ~ fn send(&mut self, msg: &str); 3 | } - ... +... 56 | impl Messenger for MockMessenger { 57 ~ fn send(&mut self, message: &str) { | diff --git a/rustbook-en/listings/ch16-fearless-concurrency/listing-16-14/output.txt b/rustbook-en/listings/ch16-fearless-concurrency/listing-16-14/output.txt index cb4167a5b..cc96baed1 100644 --- a/rustbook-en/listings/ch16-fearless-concurrency/listing-16-14/output.txt +++ b/rustbook-en/listings/ch16-fearless-concurrency/listing-16-14/output.txt @@ -22,7 +22,7 @@ note: required because it's used within this closure 11 | let handle = thread::spawn(move || { | ^^^^^^^ note: required by a bound in `spawn` - --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:691:1 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:688:1 For more information about this error, try `rustc --explain E0277`. error: could not compile `shared-state` (bin "shared-state") due to 1 previous error diff --git a/rustbook-en/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt b/rustbook-en/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt index bc736bd68..3a2342639 100644 --- a/rustbook-en/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt +++ b/rustbook-en/listings/ch19-advanced-features/no-listing-18-returns-closure/output.txt @@ -6,11 +6,11 @@ error[E0746]: return type cannot have an unboxed trait object 1 | fn returns_closure() -> dyn Fn(i32) -> i32 { | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | -help: return an `impl Trait` instead of a `dyn Trait`, if all returned values are the same type +help: consider returning an `impl Trait` instead of a `dyn Trait` | 1 | fn returns_closure() -> impl Fn(i32) -> i32 { | ~~~~ -help: box the return type, and wrap all of the returned values in `Box::new` +help: alternatively, box the return type, and wrap all of the returned values in `Box::new` | 1 ~ fn returns_closure() -> Box i32> { 2 ~ Box::new(|x| x + 1) diff --git a/rustbook-en/listings/ch20-web-server/listing-20-02/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-02/src/main.rs index f139846c6..1eff2eef3 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-02/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-02/src/main.rs @@ -14,7 +14,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let http_request: Vec<_> = buf_reader .lines() .map(|result| result.unwrap()) diff --git a/rustbook-en/listings/ch20-web-server/listing-20-03/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-03/src/main.rs index c72d4a9c6..17c8401d4 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-03/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-03/src/main.rs @@ -15,7 +15,7 @@ fn main() { // ANCHOR: here fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let http_request: Vec<_> = buf_reader .lines() .map(|result| result.unwrap()) diff --git a/rustbook-en/listings/ch20-web-server/listing-20-05/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-05/src/main.rs index d4b78b640..437d9b626 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-05/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-05/src/main.rs @@ -19,7 +19,7 @@ fn main() { // ANCHOR: here fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let http_request: Vec<_> = buf_reader .lines() .map(|result| result.unwrap()) diff --git a/rustbook-en/listings/ch20-web-server/listing-20-06/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-06/src/main.rs index 5523a42d7..843d84676 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-06/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-06/src/main.rs @@ -17,7 +17,7 @@ fn main() { // --snip-- fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); if request_line == "GET / HTTP/1.1" { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-07/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-07/src/main.rs index a14b7d538..e19467b83 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-07/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-07/src/main.rs @@ -15,7 +15,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); if request_line == "GET / HTTP/1.1" { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-09/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-09/src/main.rs index ffc51e803..0f9356ab0 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-09/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-09/src/main.rs @@ -19,7 +19,7 @@ fn main() { fn handle_connection(mut stream: TcpStream) { // --snip-- // ANCHOR_END: here - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); // ANCHOR: here diff --git a/rustbook-en/listings/ch20-web-server/listing-20-10/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-10/src/main.rs index 5a18b45c0..0679ec600 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-10/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-10/src/main.rs @@ -24,7 +24,7 @@ fn handle_connection(mut stream: TcpStream) { // --snip-- // ANCHOR_END: here - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); // ANCHOR: here diff --git a/rustbook-en/listings/ch20-web-server/listing-20-11/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-11/src/main.rs index 1181357b0..075a0d9de 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-11/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-11/src/main.rs @@ -21,7 +21,7 @@ fn main() { // ANCHOR_END: here fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-12/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-12/src/main.rs index 21b9a80f1..bde3e29d1 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-12/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-12/src/main.rs @@ -22,7 +22,7 @@ fn main() { // ANCHOR_END: here fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-13/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-13/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-13/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-13/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-14/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-14/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-14/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-14/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-15/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-15/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-15/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-15/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-16/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-16/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-16/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-16/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-17/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-17/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-17/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-17/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-18/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-18/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-18/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-18/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-19/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-19/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-19/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-19/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-20/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-20/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-20/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-20/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-21/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-21/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-21/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-21/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-22/output.txt b/rustbook-en/listings/ch20-web-server/listing-20-22/output.txt index 84ebe928b..554bfd859 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-22/output.txt +++ b/rustbook-en/listings/ch20-web-server/listing-20-22/output.txt @@ -9,7 +9,7 @@ error[E0507]: cannot move out of `worker.thread` which is behind a mutable refer | move occurs because `worker.thread` has type `JoinHandle<()>`, which does not implement the `Copy` trait | note: `JoinHandle::::join` takes ownership of the receiver `self`, which moves `worker.thread` - --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:1718:17 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:17 For more information about this error, try `rustc --explain E0507`. error: could not compile `hello` (lib) due to 1 previous error diff --git a/rustbook-en/listings/ch20-web-server/listing-20-22/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-22/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-22/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-22/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-23/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-23/src/main.rs index b6aa046d1..acd703f27 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-23/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-23/src/main.rs @@ -23,7 +23,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-24/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-24/src/main.rs index b6aa046d1..acd703f27 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-24/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-24/src/main.rs @@ -23,7 +23,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/listing-20-25/src/main.rs b/rustbook-en/listings/ch20-web-server/listing-20-25/src/main.rs index 86e8d9e78..ee0f1efe7 100644 --- a/rustbook-en/listings/ch20-web-server/listing-20-25/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/listing-20-25/src/main.rs @@ -25,7 +25,7 @@ fn main() { // ANCHOR_END: here fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs index f7b42167f..e68f72c70 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-01-define-threadpool-struct/src/main.rs @@ -23,7 +23,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-02-impl-threadpool-new/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-03-define-execute/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt b/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt index 1ffe5206b..6867dcbca 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt +++ b/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt @@ -7,7 +7,7 @@ error[E0599]: no method named `join` found for enum `Option` in the current scop | ^^^^ method not found in `Option>` | note: the method `join` exists on the type `JoinHandle<()>` - --> /rustc/129f3b9964af4d4a709d1383930ade12dfe7c081/library/std/src/thread/mod.rs:1718:5 + --> /rustc/eeb90cda1969383f56a2637cbd3037bdf598841c/library/std/src/thread/mod.rs:1778:5 help: consider using `Option::expect` to unwrap the `JoinHandle<()>` value, panicking if the value is an `Option::None` | 52 | worker.thread.expect("REASON").join().unwrap(); diff --git a/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-04-update-worker-definition/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs index 79efb28a2..1f075fde5 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-05-fix-worker-new/src/main.rs @@ -21,7 +21,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs index b6aa046d1..acd703f27 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-06-fix-threadpool-drop/src/main.rs @@ -23,7 +23,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/listings/ch20-web-server/no-listing-07-final-code/src/main.rs b/rustbook-en/listings/ch20-web-server/no-listing-07-final-code/src/main.rs index b6aa046d1..acd703f27 100644 --- a/rustbook-en/listings/ch20-web-server/no-listing-07-final-code/src/main.rs +++ b/rustbook-en/listings/ch20-web-server/no-listing-07-final-code/src/main.rs @@ -23,7 +23,7 @@ fn main() { } fn handle_connection(mut stream: TcpStream) { - let buf_reader = BufReader::new(&mut stream); + let buf_reader = BufReader::new(&stream); let request_line = buf_reader.lines().next().unwrap().unwrap(); let (status_line, filename) = match &request_line[..] { diff --git a/rustbook-en/packages/tools/src/bin/release_listings.rs b/rustbook-en/packages/tools/src/bin/release_listings.rs index c9a2f4597..09fb20976 100644 --- a/rustbook-en/packages/tools/src/bin/release_listings.rs +++ b/rustbook-en/packages/tools/src/bin/release_listings.rs @@ -28,26 +28,59 @@ fn main() -> Result<(), Box> { let chapter = chapter?; let chapter_path = chapter.path(); + if !chapter_path.is_dir() { + eprintln!( + "'{}' is not a directory, skipping", + chapter_path.display() + ); + continue; + } + let chapter_name = chapter_path .file_name() .expect("Chapter should've had a name"); // Create a corresponding chapter dir in `tmp/listings` let output_chapter_path = out_dir.join(chapter_name); - fs::create_dir(&output_chapter_path)?; + fs::create_dir(&output_chapter_path).map_err(|e| { + format!( + "could not create dir at '{}': {e}", + output_chapter_path.display() + ) + })?; // For each listing in the chapter directory, - for listing in fs::read_dir(chapter_path)? { - let listing = listing?; + for listing in fs::read_dir(&chapter_path).map_err(|e| { + format!("Could not read '{}': {e}", chapter_path.display()) + })? { + let listing = listing.map_err(|e| { + format!( + "bad dir entry listing in {}: {e}", + chapter_path.display() + ) + })?; let listing_path = listing.path(); + if !listing_path.is_dir() { + eprintln!( + "'{}' is not a directory, skipping", + chapter_path.display() + ); + continue; + } + let listing_name = listing_path .file_name() .expect("Listing should've had a name"); // Create a corresponding listing dir in the tmp chapter dir let output_listing_dir = output_chapter_path.join(listing_name); - fs::create_dir(&output_listing_dir)?; + fs::create_dir(&output_listing_dir).map_err(|e| { + format!( + "could not create dir '{}': {e}", + output_listing_dir.display() + ) + })?; // Copy all the cleaned files in the listing to the tmp directory copy_cleaned_listing_files(listing_path, output_listing_dir)?; @@ -79,8 +112,12 @@ fn copy_cleaned_listing_files( from: PathBuf, to: PathBuf, ) -> Result<(), Box> { - for item in fs::read_dir(from)? { - let item = item?; + for item in fs::read_dir(&from).map_err(|e| { + format!("Could not read_dir on '{}': {e}", from.display()) + })? { + let item = item.map_err(|e| { + format!("invalid dir entry in {}: {e}", from.display()) + })?; let item_path = item.path(); let item_name = @@ -90,7 +127,12 @@ fn copy_cleaned_listing_files( if item_path.is_dir() { // Don't copy `target` directories if item_name != "target" { - fs::create_dir(&output_item)?; + fs::create_dir(&output_item).map_err(|e| { + format!( + "Could not create output directory '{}': {e}", + output_item.display() + ) + })?; copy_cleaned_listing_files(item_path, output_item)?; } } else { @@ -105,7 +147,13 @@ fn copy_cleaned_listing_files( )?; } else { // Copy any non-Rust files without modification - fs::copy(item_path, output_item)?; + fs::copy(&item_path, &output_item).map_err(|e| { + format!( + "Could not copy from '{}' to '{}': {e}", + item_path.display(), + output_item.display() + ) + })?; } } } diff --git a/rustbook-en/rust-toolchain b/rustbook-en/rust-toolchain index 17420a571..ea3769f29 100644 --- a/rustbook-en/rust-toolchain +++ b/rustbook-en/rust-toolchain @@ -1 +1 @@ -1.79 +1.81 diff --git a/rustbook-en/src/ch01-03-hello-cargo.md b/rustbook-en/src/ch01-03-hello-cargo.md index 5750e4f01..dea721d38 100644 --- a/rustbook-en/src/ch01-03-hello-cargo.md +++ b/rustbook-en/src/ch01-03-hello-cargo.md @@ -113,7 +113,8 @@ everything is in its place. If you started a project that doesn’t use Cargo, as we did with the “Hello, world!” project, you can convert it to a project that does use Cargo. Move the project code into the *src* directory and create an appropriate *Cargo.toml* -file. +file. One easy way to get that *Cargo.toml* file is to run `cargo init`, which +will create it for you automatically. ### Building and Running a Cargo Project diff --git a/rustbook-en/src/ch20-01-single-threaded.md b/rustbook-en/src/ch20-01-single-threaded.md index 9e7fe865b..b474d926f 100644 --- a/rustbook-en/src/ch20-01-single-threaded.md +++ b/rustbook-en/src/ch20-01-single-threaded.md @@ -143,8 +143,8 @@ connection, we now call the new `handle_connection` function and pass the `stream` to it. In the `handle_connection` function, we create a new `BufReader` instance that -wraps a mutable reference to the `stream`. `BufReader` adds buffering by -managing calls to the `std::io::Read` trait methods for us. +wraps a reference to the `stream`. `BufReader` adds buffering by managing calls +to the `std::io::Read` trait methods for us. We create a variable named `http_request` to collect the lines of the request the browser sends to our server. We indicate that we want to collect these diff --git a/rustbook-en/src/title-page.md b/rustbook-en/src/title-page.md index dee3c84cb..613de0ddd 100644 --- a/rustbook-en/src/title-page.md +++ b/rustbook-en/src/title-page.md @@ -2,7 +2,7 @@ *by Steve Klabnik and Carol Nichols, with contributions from the Rust Community* -This version of the text assumes you’re using Rust 1.79.0 (released 2024-06-13) +This version of the text assumes you’re using Rust 1.81.0 (released 2024-09-04) or later. See the [“Installation” section of Chapter 1][install] to install or update Rust.